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 }); await message.setToExpire(false, { skipSave: true });
} }
window.Signal.Util.updateMessageBatcher.add(message.attributes); window.Signal.Util.queueUpdateMessage(message.attributes);
// notify frontend listeners // notify frontend listeners
const conversation = ConversationController.get( const conversation = ConversationController.get(

View file

@ -101,7 +101,7 @@
await message.setToExpire(false, { skipSave: true }); await message.setToExpire(false, { skipSave: true });
} }
window.Signal.Util.updateMessageBatcher.add(message.attributes); window.Signal.Util.queueUpdateMessage(message.attributes);
// notify frontend listeners // notify frontend listeners
const conversation = ConversationController.get( 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); this.remove(receipt);
} catch (error) { } catch (error) {

View file

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

View file

@ -1163,7 +1163,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
referencedMessageNotFound: false, 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 }); window.Whisper.Notifications.removeBy({ messageId: this.id });
if (!skipSave) { 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'); const id = this.get('id');
if (id && !skipSave) { 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 { incrementMessageCounter } from './incrementMessageCounter';
import { isFileDangerous } from './isFileDangerous'; import { isFileDangerous } from './isFileDangerous';
import { makeLookup } from './makeLookup'; import { makeLookup } from './makeLookup';
import { saveNewMessageBatcher, updateMessageBatcher } from './messageBatcher'; import {
queueUpdateMessage,
saveNewMessageBatcher,
setBatchingStrategy,
} from './messageBatcher';
import { missingCaseError } from './missingCaseError'; import { missingCaseError } from './missingCaseError';
import { parseRemoteClientExpiration } from './parseRemoteClientExpiration'; import { parseRemoteClientExpiration } from './parseRemoteClientExpiration';
import { sleep } from './sleep'; import { sleep } from './sleep';
@ -52,11 +56,12 @@ export {
mapToSupportLocale, mapToSupportLocale,
missingCaseError, missingCaseError,
parseRemoteClientExpiration, parseRemoteClientExpiration,
queueUpdateMessage,
saveNewMessageBatcher, saveNewMessageBatcher,
setBatchingStrategy,
sessionRecordToProtobuf, sessionRecordToProtobuf,
sessionStructureToArrayBuffer, sessionStructureToArrayBuffer,
sleep, sleep,
toWebSafeBase64, toWebSafeBase64,
updateMessageBatcher,
zkgroup, zkgroup,
}; };

View file

@ -5,7 +5,7 @@ import { MessageAttributesType } from '../model-types.d';
import { createBatcher } from './batcher'; import { createBatcher } from './batcher';
import { createWaitBatcher } from './waitBatcher'; import { createWaitBatcher } from './waitBatcher';
export const updateMessageBatcher = createBatcher<MessageAttributesType>({ const updateMessageBatcher = createBatcher<MessageAttributesType>({
wait: 500, wait: 500,
maxSize: 50, maxSize: 50,
processBatch: async (messageAttrs: Array<MessageAttributesType>) => { 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>({ export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
wait: 500, wait: 500,
maxSize: 30, maxSize: 30,