Improve cold start performance
This commit is contained in:
parent
c73e35b1b6
commit
d82ce07942
39 changed files with 911 additions and 628 deletions
8
ts/util/getMessageTimestamp.ts
Normal file
8
ts/util/getMessageTimestamp.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { Message } from '../components/conversation/media-gallery/types/Message';
|
||||
|
||||
export function getMessageTimestamp(message: Message): number {
|
||||
return message.received_at_ms || message.received_at;
|
||||
}
|
23
ts/util/incrementMessageCounter.ts
Normal file
23
ts/util/incrementMessageCounter.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { debounce } from 'lodash';
|
||||
|
||||
export function incrementMessageCounter(): number {
|
||||
if (!window.receivedAtCounter) {
|
||||
window.receivedAtCounter =
|
||||
Number(localStorage.getItem('lastReceivedAtCounter')) || Date.now();
|
||||
}
|
||||
|
||||
window.receivedAtCounter += 1;
|
||||
debouncedUpdateLastReceivedAt();
|
||||
|
||||
return window.receivedAtCounter;
|
||||
}
|
||||
|
||||
const debouncedUpdateLastReceivedAt = debounce(() => {
|
||||
localStorage.setItem(
|
||||
'lastReceivedAtCounter',
|
||||
String(window.receivedAtCounter)
|
||||
);
|
||||
}, 500);
|
|
@ -14,8 +14,10 @@ import { getStringForProfileChange } from './getStringForProfileChange';
|
|||
import { getTextWithMentions } from './getTextWithMentions';
|
||||
import { getUserAgent } from './getUserAgent';
|
||||
import { hasExpired } from './hasExpired';
|
||||
import { incrementMessageCounter } from './incrementMessageCounter';
|
||||
import { isFileDangerous } from './isFileDangerous';
|
||||
import { makeLookup } from './makeLookup';
|
||||
import { saveNewMessageBatcher, updateMessageBatcher } from './messageBatcher';
|
||||
import { missingCaseError } from './missingCaseError';
|
||||
import { parseRemoteClientExpiration } from './parseRemoteClientExpiration';
|
||||
import { sleep } from './sleep';
|
||||
|
@ -29,6 +31,8 @@ import {
|
|||
import * as zkgroup from './zkgroup';
|
||||
|
||||
export {
|
||||
GoogleChrome,
|
||||
Registration,
|
||||
arrayBufferToObjectURL,
|
||||
combineNames,
|
||||
createBatcher,
|
||||
|
@ -40,18 +44,19 @@ export {
|
|||
getStringForProfileChange,
|
||||
getTextWithMentions,
|
||||
getUserAgent,
|
||||
GoogleChrome,
|
||||
hasExpired,
|
||||
incrementMessageCounter,
|
||||
isFileDangerous,
|
||||
longRunningTaskWrapper,
|
||||
makeLookup,
|
||||
mapToSupportLocale,
|
||||
missingCaseError,
|
||||
parseRemoteClientExpiration,
|
||||
Registration,
|
||||
saveNewMessageBatcher,
|
||||
sessionRecordToProtobuf,
|
||||
sessionStructureToArrayBuffer,
|
||||
sleep,
|
||||
toWebSafeBase64,
|
||||
updateMessageBatcher,
|
||||
zkgroup,
|
||||
};
|
||||
|
|
|
@ -15022,7 +15022,7 @@
|
|||
"rule": "React-createRef",
|
||||
"path": "ts/components/conversation/media-gallery/MediaGallery.js",
|
||||
"line": " this.focusRef = react_1.default.createRef();",
|
||||
"lineNumber": 31,
|
||||
"lineNumber": 32,
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2019-11-01T22:46:33.013Z",
|
||||
"reasonDetail": "Used for setting focus only"
|
||||
|
@ -15031,7 +15031,7 @@
|
|||
"rule": "React-createRef",
|
||||
"path": "ts/components/conversation/media-gallery/MediaGallery.tsx",
|
||||
"line": " public readonly focusRef: React.RefObject<HTMLDivElement> = React.createRef();",
|
||||
"lineNumber": 71,
|
||||
"lineNumber": 72,
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2019-11-01T22:46:33.013Z",
|
||||
"reasonDetail": "Used for setting focus only"
|
||||
|
|
24
ts/util/messageBatcher.ts
Normal file
24
ts/util/messageBatcher.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { MessageAttributesType } from '../model-types.d';
|
||||
import { createBatcher } from './batcher';
|
||||
import { createWaitBatcher } from './waitBatcher';
|
||||
|
||||
export const updateMessageBatcher = createBatcher<MessageAttributesType>({
|
||||
wait: 500,
|
||||
maxSize: 50,
|
||||
processBatch: async (messages: Array<MessageAttributesType>) => {
|
||||
window.log.info('updateMessageBatcher', messages.length);
|
||||
await window.Signal.Data.saveMessages(messages, {});
|
||||
},
|
||||
});
|
||||
|
||||
export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
|
||||
wait: 500,
|
||||
maxSize: 30,
|
||||
processBatch: async (messages: Array<MessageAttributesType>) => {
|
||||
window.log.info('saveNewMessageBatcher', messages.length);
|
||||
await window.Signal.Data.saveMessages(messages, { forceSave: true });
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue