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,
app,
);
await serverSystem.init();
await serverSystem.init(true);
app.listen({
hostname: httpHostname,
port: httpServerPort,

View File

@ -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");