From 546139e82f151b35d6492b7cbf2ac89dbfd5d0b5 Mon Sep 17 00:00:00 2001 From: kamtschatka Date: Sun, 9 Jun 2024 20:11:23 +0200 Subject: fix: Trigger search re-index on bookmark tag manual updates. Fixes #208 (#210) * re-index of database is not scanning all places when bookmark tags are changed. Manual indexing is working as workaround #208 introduced a new function to trigger a reindex to reduce copy/paste added missing reindexes when tags are deleted/bookmarks are updated * give functions a bit more descriptive name --------- Co-authored-by: kamtschatka Co-authored-by: MohamedBassem --- packages/trpc/routers/bookmarks.ts | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'packages/trpc/routers/bookmarks.ts') diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 5f53dd16..15a8c7c0 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -22,7 +22,8 @@ import { deleteAsset } from "@hoarder/shared/assetdb"; import { LinkCrawlerQueue, OpenAIQueue, - SearchIndexingQueue, + triggerSearchDeletion, + triggerSearchReindex, } from "@hoarder/shared/queues"; import { getSearchIdxClient } from "@hoarder/shared/search"; import { @@ -295,10 +296,7 @@ export const bookmarksAppRouter = router({ break; } } - SearchIndexingQueue.add("search_indexing", { - bookmarkId: bookmark.id, - type: "index", - }); + triggerSearchReindex(bookmark.id); return bookmark; }), @@ -328,10 +326,7 @@ export const bookmarksAppRouter = router({ message: "Bookmark not found", }); } - SearchIndexingQueue.add("search_indexing", { - bookmarkId: input.bookmarkId, - type: "index", - }); + triggerSearchReindex(input.bookmarkId); return res[0]; }), @@ -357,10 +352,7 @@ export const bookmarksAppRouter = router({ message: "Bookmark not found", }); } - SearchIndexingQueue.add("search_indexing", { - bookmarkId: input.bookmarkId, - type: "index", - }); + triggerSearchReindex(input.bookmarkId); }), deleteBookmark: authedProcedure @@ -385,10 +377,7 @@ export const bookmarksAppRouter = router({ eq(bookmarks.id, input.bookmarkId), ), ); - SearchIndexingQueue.add("search_indexing", { - bookmarkId: input.bookmarkId, - type: "delete", - }); + triggerSearchDeletion(input.bookmarkId); if (deleted.changes > 0 && bookmark) { await cleanupAssetForBookmark({ asset: bookmark.asset, @@ -708,6 +697,7 @@ export const bookmarksAppRouter = router({ })), ) .onConflictDoNothing(); + triggerSearchReindex(input.bookmarkId); return { bookmarkId: input.bookmarkId, attached: allIds, -- cgit v1.2.3-70-g09d2