Make most message attribute uses readonly
Co-authored-by: Jamie Kyle <jamie@signal.org>
This commit is contained in:
parent
c619a7b6fd
commit
3555ccc629
53 changed files with 342 additions and 258 deletions
|
@ -1,17 +1,17 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import type { ReadonlyMessageAttributesType } from '../model-types.d';
|
||||
import { createBatcher } from './batcher';
|
||||
import { createWaitBatcher } from './waitBatcher';
|
||||
import { DataWriter } from '../sql/Client';
|
||||
import * as log from '../logging/log';
|
||||
|
||||
const updateMessageBatcher = createBatcher<MessageAttributesType>({
|
||||
const updateMessageBatcher = createBatcher<ReadonlyMessageAttributesType>({
|
||||
name: 'messageBatcher.updateMessageBatcher',
|
||||
wait: 75,
|
||||
maxSize: 50,
|
||||
processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
|
||||
processBatch: async (messageAttrs: Array<ReadonlyMessageAttributesType>) => {
|
||||
log.info('updateMessageBatcher', messageAttrs.length);
|
||||
|
||||
// Grab the latest from the cache in case they've changed
|
||||
|
@ -27,7 +27,9 @@ const updateMessageBatcher = createBatcher<MessageAttributesType>({
|
|||
|
||||
let shouldBatch = true;
|
||||
|
||||
export function queueUpdateMessage(messageAttr: MessageAttributesType): void {
|
||||
export function queueUpdateMessage(
|
||||
messageAttr: ReadonlyMessageAttributesType
|
||||
): void {
|
||||
if (shouldBatch) {
|
||||
updateMessageBatcher.add(messageAttr);
|
||||
} else {
|
||||
|
@ -41,21 +43,24 @@ export function setBatchingStrategy(keepBatching = false): void {
|
|||
shouldBatch = keepBatching;
|
||||
}
|
||||
|
||||
export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
|
||||
name: 'messageBatcher.saveNewMessageBatcher',
|
||||
wait: 75,
|
||||
maxSize: 30,
|
||||
processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
|
||||
log.info('saveNewMessageBatcher', messageAttrs.length);
|
||||
export const saveNewMessageBatcher =
|
||||
createWaitBatcher<ReadonlyMessageAttributesType>({
|
||||
name: 'messageBatcher.saveNewMessageBatcher',
|
||||
wait: 75,
|
||||
maxSize: 30,
|
||||
processBatch: async (
|
||||
messageAttrs: Array<ReadonlyMessageAttributesType>
|
||||
) => {
|
||||
log.info('saveNewMessageBatcher', messageAttrs.length);
|
||||
|
||||
// Grab the latest from the cache in case they've changed
|
||||
const messagesToSave = messageAttrs.map(
|
||||
message => window.MessageCache.accessAttributes(message.id) ?? message
|
||||
);
|
||||
// Grab the latest from the cache in case they've changed
|
||||
const messagesToSave = messageAttrs.map(
|
||||
message => window.MessageCache.accessAttributes(message.id) ?? message
|
||||
);
|
||||
|
||||
await DataWriter.saveMessages(messagesToSave, {
|
||||
forceSave: true,
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
},
|
||||
});
|
||||
await DataWriter.saveMessages(messagesToSave, {
|
||||
forceSave: true,
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue