From b0a7a71e2509964d4b10673c0a93ba9f33698ae6 Mon Sep 17 00:00:00 2001 From: geoffreychen777 Date: Mon, 4 Mar 2024 22:42:04 +0000 Subject: [PATCH] Add: updateCache option for paperService.update --- app/renderer/services/paper-service.ts | 28 +++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/renderer/services/paper-service.ts b/app/renderer/services/paper-service.ts index e845e90d..6fc5309b 100644 --- a/app/renderer/services/paper-service.ts +++ b/app/renderer/services/paper-service.ts @@ -257,12 +257,14 @@ export class PaperService extends Eventable { /** * Update paper entities. * @param paperEntityDrafts - paper entity drafts + * @param updateCache - Update cache, default is true * @returns Updated paper entities */ @processing(ProcessingKey.General) @errorcatching("Failed to update paper entities.", true, "PaperService", []) async update( - paperEntityDrafts: IPaperEntityCollection + paperEntityDrafts: IPaperEntityCollection, + updateCache: boolean = true ): Promise { if (this._databaseCore.getState("dbInitializing")) { return []; @@ -387,7 +389,9 @@ export class PaperService extends Eventable { ) as IPaperEntityCollection; // Don't wait this - this._cacheService.updateFullTextCache(successfulEntityDrafts); + if (updateCache) { + this._cacheService.updateFullTextCache(successfulEntityDrafts); + } return successfulEntityDrafts; } @@ -422,23 +426,15 @@ export class PaperService extends Eventable { paperEntityDrafts = paperEntityDrafts.map((paperEntityDraft) => { if (type === CategorizerType.PaperTag) { - paperEntityDraft.tags = paperEntityDraft.tags.filter((tag) => { - if (categorizer._id) { - return `${tag._id}` !== `${categorizer._id}`; - } else { - return tag.name !== categorizer.name; - } - }); + paperEntityDraft.tags = paperEntityDraft.tags.filter( + (tag) => `${tag._id}` !== `${categorizer._id}` + ); paperEntityDraft.tags.push(new PaperTag(categorizer)); } else if (type === CategorizerType.PaperFolder) { - paperEntityDraft.folders = paperEntityDraft.folders.filter((folder) => { - if (categorizer._id) { - return `${folder._id}` !== `${categorizer._id}`; - } else { - return folder.name !== categorizer.name; - } - }); + paperEntityDraft.folders = paperEntityDraft.folders.filter( + (folder) => `${folder._id}` !== `${categorizer._id}` + ); paperEntityDraft.folders.push(new PaperFolder(categorizer)); }