Optimizations to the performance improvement changes

This commit is contained in:
Josh Perez 2021-03-09 14:11:52 -05:00 committed by Josh Perez
parent cee8207e72
commit 468d491d34
7 changed files with 109 additions and 11 deletions

View File

@ -100,9 +100,7 @@
await message.setToExpire(false, { skipSave: true });
}
await window.Signal.Data.saveMessage(message.attributes, {
Message: Whisper.Message,
});
window.Signal.Util.updateMessageBatcher.add(message.attributes);
// notify frontend listeners
const conversation = ConversationController.get(

View File

@ -101,9 +101,7 @@
await message.setToExpire(false, { skipSave: true });
}
await window.Signal.Data.saveMessage(message.attributes, {
Message: Whisper.Message,
});
window.Signal.Util.updateMessageBatcher.add(message.attributes);
// notify frontend listeners
const conversation = ConversationController.get(

View File

@ -94,9 +94,7 @@
}
}
await window.Signal.Data.saveMessage(message.attributes, {
Message: Whisper.Message,
});
window.Signal.Util.updateMessageBatcher.add(message.attributes);
this.remove(receipt);
} catch (error) {

View File

@ -956,7 +956,7 @@ app.on('ready', async () => {
// 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.
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'));

View File

@ -2062,6 +2062,10 @@ export async function startApp(): Promise<void> {
interval = null;
view.onEmpty();
window.logAppLoadedEvent();
window.log.info(
'App loaded - messages:',
messageReceiver.getProcessedCount()
);
const attachmentDownloadQueue = window.attachmentDownloadQueue || [];
const THREE_DAYS_AGO = Date.now() - 3600 * 72 * 1000;
const MAX_ATTACHMENT_MSGS_TO_DOWNLOAD = 250;

View File

@ -2595,7 +2595,94 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
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
// 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> {
const attachmentsToQueue = this.get('attachments') || [];
const messageId = this.id;
@ -3008,7 +3095,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const inMemoryMessage = window.MessageController.findBySender(
this.getSenderIdentifier()
);
if (!inMemoryMessage) {
if (inMemoryMessage) {
window.log.info(
'handleDataMessage: cache hit',
this.getSenderIdentifier()
);
} else {
window.log.info(
'handleDataMessage: duplicate check db lookup needed',
this.getSenderIdentifier()
@ -3639,6 +3731,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
(isImage(attachments) || isVideo(attachments)) &&
isInCall(reduxState);
if (
this.hasAttachmentDownloads() &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(this.getConversation()!.getAccepted() || message.isOutgoing()) &&
!shouldHoldOffDownload

View File

@ -124,6 +124,8 @@ class MessageReceiverInner extends EventTarget {
count: number;
processedCount: number;
deviceId?: number;
hasConnected?: boolean;
@ -170,6 +172,7 @@ class MessageReceiverInner extends EventTarget {
super();
this.count = 0;
this.processedCount = 0;
this.signalingKey = signalingKey;
this.username = oldUsername;
@ -784,6 +787,7 @@ class MessageReceiverInner extends EventTarget {
removeFromCache(envelope: EnvelopeClass) {
const { id } = envelope;
this.cacheRemoveBatcher.add(id);
this.processedCount += 1;
}
// 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);
inner.connect();
this.getProcessedCount = () => inner.processedCount;
}
addEventListener: (name: string, handler: Function) => void;
@ -2420,6 +2425,8 @@ export default class MessageReceiver {
cleanupSessionResets: () => void;
getProcessedCount: () => number;
static stringToArrayBuffer = MessageReceiverInner.stringToArrayBuffer;
static arrayBufferToString = MessageReceiverInner.arrayBufferToString;