Batch deleteSentProtoRecipient queries

This commit is contained in:
Fedor Indutny 2021-08-31 14:35:01 -07:00 committed by GitHub
parent b71e4875e6
commit 6f3191117f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 151 additions and 81 deletions

View file

@ -13,11 +13,13 @@ import { isOutgoing } from '../state/selectors/message';
import { isDirectConversation } from '../util/whatTypeOfConversation';
import { getOwn } from '../util/getOwn';
import { missingCaseError } from '../util/missingCaseError';
import { createWaitBatcher } from '../util/waitBatcher';
import {
SendActionType,
SendStatus,
sendStateReducer,
} from '../messages/MessageSendState';
import type { DeleteSentProtoRecipientOptionsType } from '../sql/Interface';
import dataInterface from '../sql/Client';
const { deleteSentProtoRecipient } = dataInterface;
@ -40,6 +42,18 @@ class MessageReceiptModel extends Model<MessageReceiptAttributesType> {}
let singleton: MessageReceipts | undefined;
const deleteSentProtoBatcher = createWaitBatcher({
name: 'deleteSentProtoBatcher',
wait: 250,
maxSize: 30,
async processBatch(items: Array<DeleteSentProtoRecipientOptionsType>) {
window.log.info(
`MessageReceipts: Batching ${items.length} sent proto recipients deletes`
);
await deleteSentProtoRecipient(items);
},
});
async function getTargetMessage(
sourceId: string,
messages: MessageModelCollectionType
@ -202,7 +216,7 @@ export class MessageReceipts extends Collection<MessageReceiptModel> {
const deviceId = receipt.get('sourceDevice');
if (recipientUuid && deviceId) {
await deleteSentProtoRecipient({
await deleteSentProtoBatcher.add({
timestamp: messageSentAt,
recipientUuid,
deviceId,