Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(workers): remove bookmarks deleted mid-indexing from the search index

Mohamed Bassembca289d2b29c
diff --git a/apps/workers/workers/searchWorker.ts b/apps/workers/workers/searchWorker.ts
index e8d57e60..65e17ed9 100644
--- a/apps/workers/workers/searchWorker.ts
+++ b/apps/workers/workers/searchWorker.ts
@@ -123,6 +123,20 @@ async function runIndex(
});
await searchClient.addDocuments([document], { batch });
+
+ // The bookmark might have been deleted while we were building the document,
+ // and its delete could have reached the index before our add. If it's gone
+ // now, remove it. Otherwise, the delete gets enqueued after our add landed.
+ const stillExists = await db.query.bookmarks.findFirst({
+ where: eq(bookmarks.id, bookmarkId),
+ columns: { id: true },
+ });
+ if (!stillExists) {
+ logger.info(
+ `[search] Bookmark ${bookmarkId} was deleted while indexing, removing it from the index ...`,
+ );
+ await searchClient.deleteDocuments([bookmarkId], { batch });
+ }
}
async function runDelete(