This commit is contained in:
2024-06-06 16:27:18 +08:00
parent e59716f552
commit 8234cc3d44
3 changed files with 12 additions and 3 deletions

View File

@@ -4,7 +4,7 @@ import {
MeiliSearch,
MeiliSearchApiError,
} from "meilisearch";
import { sleep } from "./utils.ts";
import { sleep, toJSON } from "./utils.ts";
import type { EhDb } from "./db.ts";
import isEqual from "lodash/isEqual";
@@ -141,7 +141,8 @@ export class MeiliSearchServer {
e.tags = this.db.get_gtags_full(gid);
return e;
});
await this.waitTask(gmeta.updateDocuments(datas));
const d = JSON.parse(toJSON(datas));
await this.waitTask(gmeta.updateDocuments(d));
}
async waitTask(task: EnqueuedTask | Promise<EnqueuedTask>) {
if (task instanceof Promise) {

View File

@@ -157,6 +157,14 @@ export const handler: Handlers = {
} catch (e) {
return return_error(500, e.message);
}
} else if (typ == "update_meili_search_data") {
const gid = await parse_big_int(form.get("gid"), 0);
try {
const task = await t.add_update_meili_search_data_task(gid);
return return_data(task, 201);
} catch (e) {
return return_error(500, e.message);
}
} else {
return return_error(5, "unknown type");
}

View File

@@ -157,7 +157,7 @@ export class TaskManager extends EventTarget {
};
return await this.#add_task(task);
}
async add_update_meili_search_data_task(gid?: number) {
async add_update_meili_search_data_task(gid?: number | bigint) {
this.#check_closed();
const otask = await this.db.check_update_meili_search_data_task(gid);
if (otask !== undefined) {