Optimizations to the performance improvement changes
This commit is contained in:
parent
cee8207e72
commit
468d491d34
7 changed files with 109 additions and 11 deletions
|
@ -100,9 +100,7 @@
|
||||||
await message.setToExpire(false, { skipSave: true });
|
await message.setToExpire(false, { skipSave: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
await window.Signal.Data.saveMessage(message.attributes, {
|
window.Signal.Util.updateMessageBatcher.add(message.attributes);
|
||||||
Message: Whisper.Message,
|
|
||||||
});
|
|
||||||
|
|
||||||
// notify frontend listeners
|
// notify frontend listeners
|
||||||
const conversation = ConversationController.get(
|
const conversation = ConversationController.get(
|
||||||
|
|
|
@ -101,9 +101,7 @@
|
||||||
await message.setToExpire(false, { skipSave: true });
|
await message.setToExpire(false, { skipSave: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
await window.Signal.Data.saveMessage(message.attributes, {
|
window.Signal.Util.updateMessageBatcher.add(message.attributes);
|
||||||
Message: Whisper.Message,
|
|
||||||
});
|
|
||||||
|
|
||||||
// notify frontend listeners
|
// notify frontend listeners
|
||||||
const conversation = ConversationController.get(
|
const conversation = ConversationController.get(
|
||||||
|
|
|
@ -94,9 +94,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await window.Signal.Data.saveMessage(message.attributes, {
|
window.Signal.Util.updateMessageBatcher.add(message.attributes);
|
||||||
Message: Whisper.Message,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.remove(receipt);
|
this.remove(receipt);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
2
main.js
2
main.js
|
@ -956,7 +956,7 @@ app.on('ready', async () => {
|
||||||
// We use this event only a single time to log the startup time of the app
|
// We use this event only a single time to log the startup time of the app
|
||||||
// from when it's first ready until the loading screen disappears.
|
// from when it's first ready until the loading screen disappears.
|
||||||
ipc.once('signal-app-loaded', () => {
|
ipc.once('signal-app-loaded', () => {
|
||||||
console.log('App has finished loading in:', Date.now() - startTime);
|
console.log('App loaded - time:', Date.now() - startTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
const userDataPath = await getRealPath(app.getPath('userData'));
|
const userDataPath = await getRealPath(app.getPath('userData'));
|
||||||
|
|
|
@ -2062,6 +2062,10 @@ export async function startApp(): Promise<void> {
|
||||||
interval = null;
|
interval = null;
|
||||||
view.onEmpty();
|
view.onEmpty();
|
||||||
window.logAppLoadedEvent();
|
window.logAppLoadedEvent();
|
||||||
|
window.log.info(
|
||||||
|
'App loaded - messages:',
|
||||||
|
messageReceiver.getProcessedCount()
|
||||||
|
);
|
||||||
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;
|
||||||
|
|
|
@ -2595,7 +2595,94 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
return this.syncPromise;
|
return this.syncPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: If you're modifying this function then you'll likely also need
|
||||||
|
// to modify queueAttachmentDownloads since it contains the logic below
|
||||||
|
hasAttachmentDownloads(): boolean {
|
||||||
|
const attachments = this.get('attachments') || [];
|
||||||
|
|
||||||
|
const [longMessageAttachments, normalAttachments] = _.partition(
|
||||||
|
attachments,
|
||||||
|
attachment =>
|
||||||
|
attachment.contentType ===
|
||||||
|
window.Whisper.Message.LONG_MESSAGE_CONTENT_TYPE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (longMessageAttachments.length > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasNormalAttachments = normalAttachments.some(attachment => {
|
||||||
|
if (!attachment) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// We've already downloaded this!
|
||||||
|
if (attachment.path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (hasNormalAttachments) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const previews = this.get('preview') || [];
|
||||||
|
const hasPreviews = previews.some(item => {
|
||||||
|
if (!item.image) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// We've already downloaded this!
|
||||||
|
if (item.image.path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (hasPreviews) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contacts = this.get('contact') || [];
|
||||||
|
const hasContacts = contacts.some(item => {
|
||||||
|
if (!item.avatar || !item.avatar.avatar) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (item.avatar.avatar.path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (hasContacts) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const quote = this.get('quote');
|
||||||
|
const quoteAttachments =
|
||||||
|
quote && quote.attachments ? quote.attachments : [];
|
||||||
|
const hasQuoteAttachments = quoteAttachments.some(item => {
|
||||||
|
if (!item.thumbnail) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// We've already downloaded this!
|
||||||
|
if (item.thumbnail.path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (hasQuoteAttachments) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sticker = this.get('sticker');
|
||||||
|
if (sticker) {
|
||||||
|
return !sticker.data || (sticker.data && !sticker.data.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Receive logic
|
// Receive logic
|
||||||
|
// NOTE: If you're changing any logic in this function that deals with the
|
||||||
|
// count then you'll also have to modify the above function
|
||||||
|
// hasAttachmentDownloads
|
||||||
async queueAttachmentDownloads(): Promise<boolean> {
|
async queueAttachmentDownloads(): Promise<boolean> {
|
||||||
const attachmentsToQueue = this.get('attachments') || [];
|
const attachmentsToQueue = this.get('attachments') || [];
|
||||||
const messageId = this.id;
|
const messageId = this.id;
|
||||||
|
@ -3008,7 +3095,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
const inMemoryMessage = window.MessageController.findBySender(
|
const inMemoryMessage = window.MessageController.findBySender(
|
||||||
this.getSenderIdentifier()
|
this.getSenderIdentifier()
|
||||||
);
|
);
|
||||||
if (!inMemoryMessage) {
|
if (inMemoryMessage) {
|
||||||
|
window.log.info(
|
||||||
|
'handleDataMessage: cache hit',
|
||||||
|
this.getSenderIdentifier()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
window.log.info(
|
window.log.info(
|
||||||
'handleDataMessage: duplicate check db lookup needed',
|
'handleDataMessage: duplicate check db lookup needed',
|
||||||
this.getSenderIdentifier()
|
this.getSenderIdentifier()
|
||||||
|
@ -3639,6 +3731,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
(isImage(attachments) || isVideo(attachments)) &&
|
(isImage(attachments) || isVideo(attachments)) &&
|
||||||
isInCall(reduxState);
|
isInCall(reduxState);
|
||||||
if (
|
if (
|
||||||
|
this.hasAttachmentDownloads() &&
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
(this.getConversation()!.getAccepted() || message.isOutgoing()) &&
|
(this.getConversation()!.getAccepted() || message.isOutgoing()) &&
|
||||||
!shouldHoldOffDownload
|
!shouldHoldOffDownload
|
||||||
|
|
|
@ -124,6 +124,8 @@ class MessageReceiverInner extends EventTarget {
|
||||||
|
|
||||||
count: number;
|
count: number;
|
||||||
|
|
||||||
|
processedCount: number;
|
||||||
|
|
||||||
deviceId?: number;
|
deviceId?: number;
|
||||||
|
|
||||||
hasConnected?: boolean;
|
hasConnected?: boolean;
|
||||||
|
@ -170,6 +172,7 @@ class MessageReceiverInner extends EventTarget {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
this.processedCount = 0;
|
||||||
|
|
||||||
this.signalingKey = signalingKey;
|
this.signalingKey = signalingKey;
|
||||||
this.username = oldUsername;
|
this.username = oldUsername;
|
||||||
|
@ -784,6 +787,7 @@ class MessageReceiverInner extends EventTarget {
|
||||||
removeFromCache(envelope: EnvelopeClass) {
|
removeFromCache(envelope: EnvelopeClass) {
|
||||||
const { id } = envelope;
|
const { id } = envelope;
|
||||||
this.cacheRemoveBatcher.add(id);
|
this.cacheRemoveBatcher.add(id);
|
||||||
|
this.processedCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same as handleEnvelope, just without the decryption step. Necessary for handling
|
// Same as handleEnvelope, just without the decryption step. Necessary for handling
|
||||||
|
@ -2396,6 +2400,7 @@ export default class MessageReceiver {
|
||||||
this.cleanupSessionResets = inner.cleanupSessionResets.bind(inner);
|
this.cleanupSessionResets = inner.cleanupSessionResets.bind(inner);
|
||||||
|
|
||||||
inner.connect();
|
inner.connect();
|
||||||
|
this.getProcessedCount = () => inner.processedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener: (name: string, handler: Function) => void;
|
addEventListener: (name: string, handler: Function) => void;
|
||||||
|
@ -2420,6 +2425,8 @@ export default class MessageReceiver {
|
||||||
|
|
||||||
cleanupSessionResets: () => void;
|
cleanupSessionResets: () => void;
|
||||||
|
|
||||||
|
getProcessedCount: () => number;
|
||||||
|
|
||||||
static stringToArrayBuffer = MessageReceiverInner.stringToArrayBuffer;
|
static stringToArrayBuffer = MessageReceiverInner.stringToArrayBuffer;
|
||||||
|
|
||||||
static arrayBufferToString = MessageReceiverInner.arrayBufferToString;
|
static arrayBufferToString = MessageReceiverInner.arrayBufferToString;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue