Use smaller batches for receipts and syncs
This commit is contained in:
parent
8775c711ae
commit
03874a788f
4 changed files with 48 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { groupBy, map } from 'lodash';
|
||||
import { chunk, groupBy, map } from 'lodash';
|
||||
import { ConversationAttributesType } from '../model-types.d';
|
||||
import { getSendOptions } from './getSendOptions';
|
||||
import { handleMessageSend } from './handleMessageSend';
|
||||
|
@ -16,6 +16,8 @@ type ReceiptSpecType = {
|
|||
hasErrors: boolean;
|
||||
};
|
||||
|
||||
const CHUNK_SIZE = 100;
|
||||
|
||||
export async function sendReadReceiptsFor(
|
||||
conversationAttrs: ConversationAttributesType,
|
||||
items: Array<ReceiptSpecType>
|
||||
|
@ -31,23 +33,31 @@ export async function sendReadReceiptsFor(
|
|||
|
||||
await Promise.all(
|
||||
map(receiptsBySender, async (receipts, senderId) => {
|
||||
const timestamps = map(receipts, item => item.timestamp);
|
||||
const messageIds = map(receipts, item => item.messageId);
|
||||
const conversation = window.ConversationController.get(senderId);
|
||||
|
||||
if (conversation) {
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging.sendReadReceipts({
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
senderE164: conversation.get('e164')!,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
senderUuid: conversation.get('uuid')!,
|
||||
timestamps,
|
||||
options: sendOptions,
|
||||
}),
|
||||
{ messageIds, sendType: 'readReceipt' }
|
||||
);
|
||||
if (!conversation) {
|
||||
return;
|
||||
}
|
||||
|
||||
const batches = chunk(receipts, CHUNK_SIZE);
|
||||
await Promise.all(
|
||||
batches.map(batch => {
|
||||
const timestamps = map(batch, item => item.timestamp);
|
||||
const messageIds = map(batch, item => item.messageId);
|
||||
|
||||
return handleMessageSend(
|
||||
window.textsecure.messaging.sendReadReceipts({
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
senderE164: conversation.get('e164')!,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
senderUuid: conversation.get('uuid')!,
|
||||
timestamps,
|
||||
options: sendOptions,
|
||||
}),
|
||||
{ messageIds, sendType: 'readReceipt' }
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue