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

@ -100,7 +100,7 @@
await message.setToExpire(false, { skipSave: true });
}
window.Signal.Util.updateMessageBatcher.add(message.attributes);
window.Signal.Util.queueUpdateMessage(message.attributes);
// notify frontend listeners
const conversation = ConversationController.get(

View File

@ -101,7 +101,7 @@
await message.setToExpire(false, { skipSave: true });
}
window.Signal.Util.updateMessageBatcher.add(message.attributes);
window.Signal.Util.queueUpdateMessage(message.attributes);
// notify frontend listeners
const conversation = ConversationController.get(

View File

@ -94,7 +94,7 @@
}
}
window.Signal.Util.updateMessageBatcher.add(message.attributes);
window.Signal.Util.queueUpdateMessage(message.attributes);
this.remove(receipt);
} catch (error) {

View File

@ -2067,6 +2067,7 @@ export async function startApp(): Promise<void> {
messageReceiver.getProcessedCount()
);
window.sqlInitializer.goBackToMainProcess();
window.Signal.Util.setBatchingStrategy(false);
const attachmentDownloadQueue = window.attachmentDownloadQueue || [];
const THREE_DAYS_AGO = Date.now() - 3600 * 72 * 1000;
const MAX_ATTACHMENT_MSGS_TO_DOWNLOAD = 250;

View File

@ -1163,7 +1163,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
referencedMessageNotFound: false,
},
});
window.Signal.Util.updateMessageBatcher.add(this.attributes);
window.Signal.Util.queueUpdateMessage(this.attributes);
}
}
@ -1959,7 +1959,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
window.Whisper.Notifications.removeBy({ messageId: this.id });
if (!skipSave) {
window.Signal.Util.updateMessageBatcher.add(this.attributes);
window.Signal.Util.queueUpdateMessage(this.attributes);
}
}
@ -2008,7 +2008,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const id = this.get('id');
if (id && !skipSave) {
window.Signal.Util.updateMessageBatcher.add(this.attributes);
window.Signal.Util.queueUpdateMessage(this.attributes);
}
}
}

View File

@ -17,7 +17,11 @@ import { hasExpired } from './hasExpired';
import { incrementMessageCounter } from './incrementMessageCounter';
import { isFileDangerous } from './isFileDangerous';
import { makeLookup } from './makeLookup';
import { saveNewMessageBatcher, updateMessageBatcher } from './messageBatcher';
import {
queueUpdateMessage,
saveNewMessageBatcher,
setBatchingStrategy,
} from './messageBatcher';
import { missingCaseError } from './missingCaseError';
import { parseRemoteClientExpiration } from './parseRemoteClientExpiration';
import { sleep } from './sleep';
@ -52,11 +56,12 @@ export {
mapToSupportLocale,
missingCaseError,
parseRemoteClientExpiration,
queueUpdateMessage,
saveNewMessageBatcher,
setBatchingStrategy,
sessionRecordToProtobuf,
sessionStructureToArrayBuffer,
sleep,
toWebSafeBase64,
updateMessageBatcher,
zkgroup,
};

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,