Cache view syncs by sender + timestamp
This commit is contained in:
parent
8b9ac24344
commit
a3065796fe
1 changed files with 15 additions and 3 deletions
|
@ -15,6 +15,7 @@ import { markViewed } from '../services/MessageUpdater';
|
||||||
import { notificationService } from '../services/notifications';
|
import { notificationService } from '../services/notifications';
|
||||||
import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
|
import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
|
||||||
import { queueUpdateMessage } from '../util/messageBatcher';
|
import { queueUpdateMessage } from '../util/messageBatcher';
|
||||||
|
import { generateCacheKey } from './generateCacheKey';
|
||||||
|
|
||||||
export type ViewSyncAttributesType = {
|
export type ViewSyncAttributesType = {
|
||||||
envelopeId: string;
|
envelopeId: string;
|
||||||
|
@ -26,10 +27,15 @@ export type ViewSyncAttributesType = {
|
||||||
viewedAt: number;
|
viewedAt: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewSyncs = new Map<number, ViewSyncAttributesType>();
|
const viewSyncs = new Map<string, ViewSyncAttributesType>();
|
||||||
|
|
||||||
function remove(sync: ViewSyncAttributesType): void {
|
function remove(sync: ViewSyncAttributesType): void {
|
||||||
viewSyncs.delete(sync.timestamp);
|
viewSyncs.delete(
|
||||||
|
generateCacheKey({
|
||||||
|
sender: sync.senderId,
|
||||||
|
timestamp: sync.timestamp,
|
||||||
|
})
|
||||||
|
);
|
||||||
sync.removeFromMessageReceiverCache();
|
sync.removeFromMessageReceiverCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +74,13 @@ export function forMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function onSync(sync: ViewSyncAttributesType): Promise<void> {
|
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})`;
|
const logId = `ViewSyncs.onSync(timestamp=${sync.timestamp})`;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue