perf: performance improvements 1

This commit is contained in:
2026-07-14 01:34:33 +02:00
parent edc4d935d8
commit 59dfd2de85
27 changed files with 762 additions and 94 deletions
@@ -7,6 +7,7 @@ import {
import {
buildAttachmentDisplayPinKey,
canRevokeAttachmentDisplayBlob,
collectMessageIdsForInactiveRoomBlobRelease,
shouldRevokeDisplayBlobForAttachment
} from './attachment-blob-eviction.rules';
@@ -58,4 +59,40 @@ describe('attachment-blob-eviction rules', () => {
expect(shouldRevokeDisplayBlobForAttachment('msg-1', attachment, new Set())).toBe(true);
});
describe('collectMessageIdsForInactiveRoomBlobRelease', () => {
const messageRoomIds = new Map([
['msg-a', 'room-1'],
['msg-b', 'room-2'],
['msg-c', 'room-2']
]);
it('selects messages that belong to rooms other than the active one', () => {
expect(collectMessageIdsForInactiveRoomBlobRelease(
[
'msg-a',
'msg-b',
'msg-c'
],
(messageId) => messageRoomIds.get(messageId) ?? null,
'room-1'
)).toEqual(['msg-b', 'msg-c']);
});
it('skips messages with an unknown room so they are not evicted by mistake', () => {
expect(collectMessageIdsForInactiveRoomBlobRelease(
['msg-a', 'msg-unknown'],
(messageId) => messageRoomIds.get(messageId) ?? null,
'room-2'
)).toEqual(['msg-a']);
});
it('selects every known-room message when no room is active', () => {
expect(collectMessageIdsForInactiveRoomBlobRelease(
['msg-a', 'msg-b'],
(messageId) => messageRoomIds.get(messageId) ?? null,
null
)).toEqual(['msg-a', 'msg-b']);
});
});
});