From cf1b77425537b9fac90caf818d65bb9fe0c64aae Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 14 May 2024 15:19:09 +0500 Subject: [PATCH] core: filter out conflicted notes & content during sync --- packages/core/src/api/sync/collector.ts | 3 --- packages/core/src/database/sql-collection.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/src/api/sync/collector.ts b/packages/core/src/api/sync/collector.ts index 396effbc4..e3d9289a5 100644 --- a/packages/core/src/api/sync/collector.ts +++ b/packages/core/src/api/sync/collector.ts @@ -110,9 +110,6 @@ function filterSyncableItems(items: MaybeDeletedItem[]): { const ids = []; const syncableItems = []; for (const item of items) { - // do not sync conflicted note or content - if ("conflicted" in item && item.conflicted) continue; - delete item.synced; ids.push(item.id); diff --git a/packages/core/src/database/sql-collection.ts b/packages/core/src/database/sql-collection.ts index f4d6f8c9e..d78e03892 100644 --- a/packages/core/src/database/sql-collection.ts +++ b/packages/core/src/database/sql-collection.ts @@ -284,6 +284,12 @@ export class SQLCollection< .selectFrom(this.type) .select((a) => a.fn.count("id").as("count")) .where(isFalse("synced")) + .$if(this.type === "content", (eb) => + eb.where("conflicted", "is", null) + ) + .$if(this.type === "notes", (eb) => + eb.where("conflicted", "is not", true) + ) .$if(this.type === "attachments", (eb) => eb.where((eb) => eb.or([eb("dateUploaded", ">", 0), eb("deleted", "==", true)]) @@ -304,6 +310,12 @@ export class SQLCollection< .selectAll() .$if(lastRowId != null, (qb) => qb.where("id", ">", lastRowId!)) .$if(!forceSync, (eb) => eb.where(isFalse("synced"))) + .$if(this.type === "content", (eb) => + eb.where("conflicted", "is", null) + ) + .$if(this.type === "notes", (eb) => + eb.where("conflicted", "is not", true) + ) .$if(this.type === "attachments", (eb) => eb.where((eb) => eb.or([eb("dateUploaded", ">", 0), eb("deleted", "==", true)])