fix: improve fetch items progress

This commit is contained in:
thecodrr
2022-04-01 14:50:12 +05:00
parent 0d5c1990ec
commit f8bb3d2d71

View File

@@ -157,7 +157,7 @@ class Sync {
async fetch(lastSynced) { async fetch(lastSynced) {
const serverResponse = await new Promise((resolve, reject) => { 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({ this.connection.stream("FetchItems", lastSynced).subscribe({
next: (/** @type {SyncTransferItem} */ syncStatus) => { next: (/** @type {SyncTransferItem} */ syncStatus) => {
const { total, item, synced, lastSynced } = syncStatus; const { total, item, synced, lastSynced } = syncStatus;
@@ -166,17 +166,15 @@ class Sync {
return; return;
} }
if (!item) return; if (!item) return;
if (counter.queue === null) counter.queue = total;
++counter.count;
++counter.queue;
const progress = counter.count;
this.onSyncItem(syncStatus) this.onSyncItem(syncStatus)
.then(() => { .then(() => {
sendSyncProgressEvent( sendSyncProgressEvent(
this.db.eventManager, this.db.eventManager,
`download`, `download`,
total, total,
progress ++counter.count
); );
}) })
.catch(reject) .catch(reject)