Cache view syncs by sender + timestamp

This commit is contained in:
trevor-signal 2023-11-02 12:16:52 -04:00 committed by GitHub
parent 8b9ac24344
commit a3065796fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@ import { markViewed } from '../services/MessageUpdater';
import { notificationService } from '../services/notifications';
import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
import { queueUpdateMessage } from '../util/messageBatcher';
import { generateCacheKey } from './generateCacheKey';
export type ViewSyncAttributesType = {
envelopeId: string;
@ -26,10 +27,15 @@ export type ViewSyncAttributesType = {
viewedAt: number;
};
const viewSyncs = new Map<number, ViewSyncAttributesType>();
const viewSyncs = new Map<string, ViewSyncAttributesType>();
function remove(sync: ViewSyncAttributesType): void {
viewSyncs.delete(sync.timestamp);
viewSyncs.delete(
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
})
);
sync.removeFromMessageReceiverCache();
}
@ -68,7 +74,13 @@ export function forMessage(
}
export async function onSync(sync: ViewSyncAttributesType): Promise<void> {
viewSyncs.set(sync.timestamp, sync);
viewSyncs.set(
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
}),
sync
);
const logId = `ViewSyncs.onSync(timestamp=${sync.timestamp})`;