From f8bb3d2d71d9d1679b96b24a502012b1cef76a19 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Fri, 1 Apr 2022 14:50:12 +0500 Subject: [PATCH] fix: improve fetch items progress --- packages/core/api/sync/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js index 84f62be03..9dc47da5f 100644 --- a/packages/core/api/sync/index.js +++ b/packages/core/api/sync/index.js @@ -157,7 +157,7 @@ class Sync { async fetch(lastSynced) { const serverResponse = await new Promise((resolve, reject) => { - let counter = { count: 0, queue: 0 }; + let counter = { count: 0, queue: null }; this.connection.stream("FetchItems", lastSynced).subscribe({ next: (/** @type {SyncTransferItem} */ syncStatus) => { const { total, item, synced, lastSynced } = syncStatus; @@ -166,17 +166,15 @@ class Sync { return; } if (!item) return; + if (counter.queue === null) counter.queue = total; - ++counter.count; - ++counter.queue; - const progress = counter.count; this.onSyncItem(syncStatus) .then(() => { sendSyncProgressEvent( this.db.eventManager, `download`, total, - progress + ++counter.count ); }) .catch(reject)