From 05810663500be48ed5799cbfa5ea06b3fe69e1ee Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 18 Nov 2020 20:09:27 +0100 Subject: [PATCH] upload smallest attachments first so you don't get a delay at the end of the upload when starting a new request --- src/matrix/room/sending/PendingEvent.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index ad0e0566..a4fbfc03 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -108,7 +108,10 @@ export class PendingEvent { } this._status = SendStatus.UploadingAttachments; this._emitUpdate("status"); - for (const [urlPath, attachment] of Object.entries(this._attachments)) { + const entries = Object.entries(this._attachments); + // upload smallest attachments first + entries.sort(([, a1], [, a2]) => a1.size - a2.size); + for (const [urlPath, attachment] of entries) { await attachment.upload(hsApi, () => { this._emitUpdate("attachmentsSentBytes"); });