Do not batch single saveMessage calls after start-up
This commit is contained in:
parent
80e3582d01
commit
0bd3c78187
7 changed files with 31 additions and 9 deletions
|
@ -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(
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue