Use sender+timestamp to cache receipts and read syncs

This commit is contained in:
Scott Nonnenberg 2023-11-02 06:28:49 -07:00 committed by GitHub
parent 8f6fe60342
commit 0b08fc9e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 5 deletions

View file

@ -24,6 +24,7 @@ import { getSourceServiceId } from '../messages/helpers';
import { queueUpdateMessage } from '../util/messageBatcher';
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
import { getMessageIdForLogging } from '../util/idForLogging';
import { generateCacheKey } from './generateCacheKey';
const { deleteSentProtoRecipient } = dataInterface;
@ -78,7 +79,12 @@ const deleteSentProtoBatcher = createWaitBatcher({
});
function remove(receipt: MessageReceiptAttributesType): void {
receipts.delete(receipt.envelopeId);
receipts.delete(
generateCacheKey({
sender: receipt.sourceServiceId,
timestamp: receipt.messageSentAt,
})
);
receipt.removeFromMessageReceiverCache();
}
@ -341,7 +347,13 @@ async function updateMessageSendState(
export async function onReceipt(
receipt: MessageReceiptAttributesType
): Promise<void> {
receipts.set(receipt.envelopeId, receipt);
receipts.set(
generateCacheKey({
sender: receipt.sourceServiceId,
timestamp: receipt.messageSentAt,
}),
receipt
);
const { messageSentAt, sourceConversationId, sourceServiceId, type } =
receipt;