From 4281fb65e1dbd8c21b42385b38349e3d33520cb4 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 4 Mar 2024 12:05:04 +0500 Subject: [PATCH] core: do not include deleted attachments in filters --- packages/core/src/collections/attachments.ts | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/core/src/collections/attachments.ts b/packages/core/src/collections/attachments.ts index e2ade93c8..6d15c3502 100644 --- a/packages/core/src/collections/attachments.ts +++ b/packages/core/src/collections/attachments.ts @@ -415,28 +415,32 @@ export class Attachments implements ICollection { get images() { return this.collection.createFilter( - (qb) => qb.where("mimeType", "like", `image/%`), + (qb) => qb.where(isFalse("deleted")).where("mimeType", "like", `image/%`), this.db.options?.batchSize ); } get videos() { return this.collection.createFilter( - (qb) => qb.where("mimeType", "like", `video/%`), + (qb) => qb.where(isFalse("deleted")).where("mimeType", "like", `video/%`), this.db.options?.batchSize ); } get documents() { return this.collection.createFilter( - (qb) => qb.where("mimeType", "in", DocumentMimeTypes), + (qb) => + qb.where(isFalse("deleted")).where("mimeType", "in", DocumentMimeTypes), this.db.options?.batchSize ); } get webclips() { return this.collection.createFilter( - (qb) => qb.where("mimeType", "==", `application/vnd.notesnook.web-clip`), + (qb) => + qb + .where(isFalse("deleted")) + .where("mimeType", "==", `application/vnd.notesnook.web-clip`), this.db.options?.batchSize ); } @@ -444,13 +448,15 @@ export class Attachments implements ICollection { get orphaned() { return this.collection.createFilter( (qb) => - qb.where("id", "not in", (eb) => - eb - .selectFrom("relations") - .where("toType", "==", "attachment") - .select("toId as id") - .$narrowType<{ id: string }>() - ), + qb + .where(isFalse("deleted")) + .where("id", "not in", (eb) => + eb + .selectFrom("relations") + .where("toType", "==", "attachment") + .select("toId as id") + .$narrowType<{ id: string }>() + ), this.db.options?.batchSize ); }