aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2026-02-01 22:42:17 +0000
committerGitHub <noreply@github.com>2026-02-01 22:42:17 +0000
commit54243b8cc5ccd76fe23821f6e159b954a2166578 (patch)
tree45de1fa3324f8022825d521996ebc8b7ba890817 /apps
parente86188000147e0178ac6ca971f061b37daa40132 (diff)
downloadkarakeep-54243b8cc5ccd76fe23821f6e159b954a2166578.tar.zst
feat: batch meilisearch requests (#2441)
* feat: batch meilisearch requests * more fixes
Diffstat (limited to 'apps')
-rw-r--r--apps/workers/workers/searchWorker.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/apps/workers/workers/searchWorker.ts b/apps/workers/workers/searchWorker.ts
index 7a9c3a8d..b0608dce 100644
--- a/apps/workers/workers/searchWorker.ts
+++ b/apps/workers/workers/searchWorker.ts
@@ -56,7 +56,11 @@ export class SearchIndexingWorker {
}
}
-async function runIndex(searchClient: SearchIndexClient, bookmarkId: string) {
+async function runIndex(
+ searchClient: SearchIndexClient,
+ bookmarkId: string,
+ batch: boolean,
+) {
const bookmark = await db.query.bookmarks.findFirst({
where: eq(bookmarks.id, bookmarkId),
with: {
@@ -107,11 +111,15 @@ async function runIndex(searchClient: SearchIndexClient, bookmarkId: string) {
tags: bookmark.tagsOnBookmarks.map((t) => t.tag.name),
};
- await searchClient.addDocuments([document]);
+ await searchClient.addDocuments([document], { batch });
}
-async function runDelete(searchClient: SearchIndexClient, bookmarkId: string) {
- await searchClient.deleteDocuments([bookmarkId]);
+async function runDelete(
+ searchClient: SearchIndexClient,
+ bookmarkId: string,
+ batch: boolean,
+) {
+ await searchClient.deleteDocuments([bookmarkId], { batch });
}
async function runSearchIndexing(job: DequeuedJob<ZSearchIndexingRequest>) {
@@ -133,17 +141,20 @@ async function runSearchIndexing(job: DequeuedJob<ZSearchIndexingRequest>) {
}
const bookmarkId = request.data.bookmarkId;
+ // Disable batching on retries (runNumber > 0) for improved reliability
+ const batch = job.runNumber === 0;
+
logger.info(
- `[search][${jobId}] Attempting to index bookmark with id ${bookmarkId} ...`,
+ `[search][${jobId}] Attempting to index bookmark with id ${bookmarkId} (run ${job.runNumber}, batch=${batch}) ...`,
);
switch (request.data.type) {
case "index": {
- await runIndex(searchClient, bookmarkId);
+ await runIndex(searchClient, bookmarkId, batch);
break;
}
case "delete": {
- await runDelete(searchClient, bookmarkId);
+ await runDelete(searchClient, bookmarkId, batch);
break;
}
}