From 9b5fa44fb6a347415a80f951d1aaabcef3cf4e14 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 30 Aug 2023 22:36:27 +0200 Subject: [PATCH] Perform initial index --- cmd/server.ts | 4 ++-- plugs/search/engine.ts | 1 - server/server_system.ts | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/server.ts b/cmd/server.ts index 545b26ff..3e635ca4 100644 --- a/cmd/server.ts +++ b/cmd/server.ts @@ -100,10 +100,10 @@ To allow outside connections, pass -L 0.0.0.0 as a flag, and put a TLS terminato system = serverSystem.system; if (options.reindex) { console.log("Reindexing space (requested via --reindex flag)"); - await serverSystem.system.loadedPlugs.get("index")!.invoke( + serverSystem.system.loadedPlugs.get("index")!.invoke( "reindexSpace", [], - ); + ).catch(console.error); } } diff --git a/plugs/search/engine.ts b/plugs/search/engine.ts index a6b16e05..ce1f276f 100644 --- a/plugs/search/engine.ts +++ b/plugs/search/engine.ts @@ -114,6 +114,5 @@ export class SimpleSearchEngine { } await this.index.delete(keysToDelete); await this.reverseIndex.delete(revKeysToDelete); - // console.log("Deleted", documentId, keysToDelete, revKeysToDelete); } } diff --git a/server/server_system.ts b/server/server_system.ts index 64fe31a8..ae4db73d 100644 --- a/server/server_system.ts +++ b/server/server_system.ts @@ -145,6 +145,17 @@ export class ServerSystem { } })().catch(console.error); }); + + // Check if this space was ever indexed before + if (!await this.kvStore.has("$initialIndexCompleted")) { + console.log("Indexing space for the first time (in the background)"); + this.system.loadedPlugs.get("index")!.invoke( + "reindexSpace", + [], + ).then(() => { + this.kvStore.set("$initialIndexCompleted", true); + }).catch(console.error); + } } async loadPlugs() {