Do not batch single saveMessage calls after start-up

This commit is contained in:
Josh Perez 2021-03-10 22:21:21 -05:00 committed by Josh Perez
parent 80e3582d01
commit 0bd3c78187
7 changed files with 31 additions and 9 deletions

View file

@ -5,7 +5,7 @@ import { MessageAttributesType } from '../model-types.d';
import { createBatcher } from './batcher';
import { createWaitBatcher } from './waitBatcher';
export const updateMessageBatcher = createBatcher<MessageAttributesType>({
const updateMessageBatcher = createBatcher<MessageAttributesType>({
wait: 500,
maxSize: 50,
processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
@ -14,6 +14,22 @@ export const updateMessageBatcher = createBatcher<MessageAttributesType>({
},
});
let shouldBatch = true;
export function queueUpdateMessage(messageAttr: MessageAttributesType): void {
if (shouldBatch) {
updateMessageBatcher.add(messageAttr);
} else {
window.Signal.Data.saveMessage(messageAttr, {
Message: window.Whisper.Message,
});
}
}
export function setBatchingStrategy(keepBatching = false): void {
shouldBatch = keepBatching;
}
export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
wait: 500,
maxSize: 30,