1
0

Initial index on plug:run

This commit is contained in:
Zef Hemel 2023-11-02 12:46:33 +01:00
parent 2844c8bc25
commit e23b0808e0
2 changed files with 6 additions and 3 deletions

View File

@ -26,7 +26,7 @@ export async function runPlug(
dbPath, dbPath,
app, app,
); );
await serverSystem.init(); await serverSystem.init(true);
app.listen({ app.listen({
hostname: httpHostname, hostname: httpHostname,
port: httpServerPort, port: httpServerPort,

View File

@ -51,7 +51,7 @@ export class ServerSystem {
} }
// Always needs to be invoked right after construction // Always needs to be invoked right after construction
async init() { async init(awaitIndex = false) {
// Event hook // Event hook
const eventHook = new EventHook(); const eventHook = new EventHook();
this.system.addHook(eventHook); this.system.addHook(eventHook);
@ -151,12 +151,15 @@ export class ServerSystem {
// Check if this space was ever indexed before // Check if this space was ever indexed before
if (!await this.ds.get(["$initialIndexDone"])) { if (!await this.ds.get(["$initialIndexDone"])) {
console.log("Indexing space for the first time (in the background)"); 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", "reindexSpace",
[], [],
).then(() => { ).then(() => {
this.ds.set(["$initialIndexDone"], true); this.ds.set(["$initialIndexDone"], true);
}).catch(console.error); }).catch(console.error);
if (awaitIndex) {
await indexPromise;
}
} }
await eventHook.dispatchEvent("system:ready"); await eventHook.dispatchEvent("system:ready");