A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix: Reduce polling interval on meilisearch tasks
Mohamed Bassemfcfe6a53b49d
diff --git a/apps/workers/workers/searchWorker.ts b/apps/workers/workers/searchWorker.tsindex 7dd25ee8..1433ef3c 100644--- a/apps/workers/workers/searchWorker.ts+++ b/apps/workers/workers/searchWorker.ts@@ -106,7 +106,7 @@ async function runIndex(searchClient: SearchIndexClient, bookmarkId: string) {}async function runDelete(searchClient: SearchIndexClient, bookmarkId: string) {- await searchClient.deleteDocument(bookmarkId);+ await searchClient.deleteDocuments([bookmarkId]);}async function runSearchIndexing(job: DequeuedJob<ZSearchIndexingRequest>) {diff --git a/packages/plugins-search-meilisearch/src/index.ts b/packages/plugins-search-meilisearch/src/index.tsindex 6153a9c4..f0040db7 100644--- a/packages/plugins-search-meilisearch/src/index.ts+++ b/packages/plugins-search-meilisearch/src/index.ts@@ -18,48 +18,12 @@ class MeiliSearchIndexClient implements SearchIndexClient {const task = await this.index.addDocuments(documents, {primaryKey: "id",});- await this.index.waitForTask(task.taskUid);- const taskResult = await this.index.getTask(task.taskUid);- if (taskResult.error) {- throw new Error(- `MeiliSearch add documents failed: ${taskResult.error.message}`,- );- }- }-- async updateDocuments(documents: BookmarkSearchDocument[]): Promise<void> {- const task = await this.index.updateDocuments(documents, {- primaryKey: "id",- });- await this.index.waitForTask(task.taskUid);- const taskResult = await this.index.getTask(task.taskUid);- if (taskResult.error) {- throw new Error(- `MeiliSearch update documents failed: ${taskResult.error.message}`,- );- }- }-- async deleteDocument(id: string): Promise<void> {- const task = await this.index.deleteDocument(id);- await this.index.waitForTask(task.taskUid);- const taskResult = await this.index.getTask(task.taskUid);- if (taskResult.error) {- throw new Error(- `MeiliSearch delete document failed: ${taskResult.error.message}`,- );- }+ await this.ensureTaskSuccess(task.taskUid);}async deleteDocuments(ids: string[]): Promise<void> {const task = await this.index.deleteDocuments(ids);- await this.index.waitForTask(task.taskUid);- const taskResult = await this.index.getTask(task.taskUid);- if (taskResult.error) {- throw new Error(- `MeiliSearch delete documents failed: ${taskResult.error.message}`,- );- }+ await this.ensureTaskSuccess(task.taskUid);}async search(options: SearchOptions): Promise<SearchResponse> {@@ -82,12 +46,15 @@ class MeiliSearchIndexClient implements SearchIndexClient {async clearIndex(): Promise<void> {const task = await this.index.deleteAllDocuments();- await this.index.waitForTask(task.taskUid);- const taskResult = await this.index.getTask(task.taskUid);- if (taskResult.error) {- throw new Error(- `MeiliSearch clear index failed: ${taskResult.error.message}`,- );+ await this.ensureTaskSuccess(task.taskUid);+ }++ private async ensureTaskSuccess(taskUid: number): Promise<void> {+ const task = await this.index.waitForTask(taskUid, {+ intervalMs: 200,+ });+ if (task.error) {+ throw new Error(`Search task failed: ${task.error.message}`);}}}diff --git a/packages/shared/search.ts b/packages/shared/search.tsindex 2afc9763..5158f30f 100644--- a/packages/shared/search.ts+++ b/packages/shared/search.ts@@ -30,6 +30,7 @@ export interface SearchResult {}export interface SearchOptions {+ // TODO: Make query, filter and sort strongly typedquery: string;filter?: string[];limit?: number;@@ -45,8 +46,6 @@ export interface SearchResponse {export interface SearchIndexClient {addDocuments(documents: BookmarkSearchDocument[]): Promise<void>;- updateDocuments(documents: BookmarkSearchDocument[]): Promise<void>;- deleteDocument(id: string): Promise<void>;deleteDocuments(ids: string[]): Promise<void>;search(options: SearchOptions): Promise<SearchResponse>;clearIndex(): Promise<void>;