From e23b0808e0bfeb2553869bc9421f2411336767f3 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 2 Nov 2023 12:46:33 +0100 Subject: [PATCH] Initial index on plug:run --- cli/plug_run.ts | 2 +- server/server_system.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/plug_run.ts b/cli/plug_run.ts index 9d11920..cc752d4 100644 --- a/cli/plug_run.ts +++ b/cli/plug_run.ts @@ -26,7 +26,7 @@ export async function runPlug( dbPath, app, ); - await serverSystem.init(); + await serverSystem.init(true); app.listen({ hostname: httpHostname, port: httpServerPort, diff --git a/server/server_system.ts b/server/server_system.ts index 7e5b93c..ff231e6 100644 --- a/server/server_system.ts +++ b/server/server_system.ts @@ -51,7 +51,7 @@ export class ServerSystem { } // Always needs to be invoked right after construction - async init() { + async init(awaitIndex = false) { // Event hook const eventHook = new EventHook(); this.system.addHook(eventHook); @@ -151,12 +151,15 @@ export class ServerSystem { // Check if this space was ever indexed before if (!await this.ds.get(["$initialIndexDone"])) { console.log("Indexing space for the first time (in the background)"); - this.system.loadedPlugs.get("index")!.invoke( + const indexPromise = this.system.loadedPlugs.get("index")!.invoke( "reindexSpace", [], ).then(() => { this.ds.set(["$initialIndexDone"], true); }).catch(console.error); + if (awaitIndex) { + await indexPromise; + } } await eventHook.dispatchEvent("system:ready");