core: prevent recursive sync after pushing items

This commit is contained in:
Abdullah Atta
2023-12-26 15:17:29 +05:00
parent f116feb6b9
commit c5e46ab99b
2 changed files with 10 additions and 3 deletions

View File

@@ -53,7 +53,8 @@ class Collector {
await collection.update(
chunk.map((i) => i.id),
{ synced: true }
{ synced: true },
{ sendEvent: false }
);
}
}

View File

@@ -166,7 +166,11 @@ export class SQLCollection<
});
}
async update(ids: string[], partial: Partial<SQLiteItem<T>>) {
async update(
ids: string[],
partial: Partial<SQLiteItem<T>>,
options: { sendEvent: boolean } = { sendEvent: true }
) {
await this.db()
.updateTable<keyof DatabaseSchema>(this.type)
.where("id", "in", ids)
@@ -176,7 +180,9 @@ export class SQLCollection<
synced: partial.synced || false
})
.execute();
this.eventManager.publish(EVENTS.databaseUpdated, ids);
if (options.sendEvent) {
this.eventManager.publish(EVENTS.databaseUpdated, ids);
}
}
async ids(sortOptions: GroupOptions): Promise<string[]> {