From 1bb096f50326e31cfbdc2dbbca81dd7a52c47105 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 5 Aug 2024 09:15:31 +0200 Subject: [PATCH] Pre-index SETTINGS on full space reindex --- plugs/index/command.ts | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/plugs/index/command.ts b/plugs/index/command.ts index 2fcec00e..a5c85d1a 100644 --- a/plugs/index/command.ts +++ b/plugs/index/command.ts @@ -24,8 +24,12 @@ export async function reindexSpace(noClear = false) { } // Load builtins await system.invokeFunction("index.loadBuiltinsIntoIndex"); + // Pre-index SETTINGS page to get useful settings + console.log("Indexing SETTINGS page"); + await indexPage("SETTINGS"); const files = await space.listFiles(); + console.log("Queing", files.length, "pages to be indexed."); // Queue all file names to be indexed await mq.batchSend("indexQueue", files.map((file) => file.name)); @@ -49,26 +53,29 @@ export async function processIndexQueue(messages: MQMessage[]) { console.log(`Indexing file ${name}`); if (name.endsWith(".md")) { name = name.slice(0, -3); - const text = await space.readPage(name); - const parsed = await markdown.parseMarkdown(text); - if (isTemplate(text)) { - console.log("Indexing", name, "as template"); - await events.dispatchEvent("page:indexTemplate", { - name, - tree: parsed, - }); - } else { - await events.dispatchEvent("page:index", { - name, - tree: parsed, - }); - } + await indexPage(name); } else { await indexAttachment(name); } } } +async function indexPage(name: string) { + const text = await space.readPage(name); + const parsed = await markdown.parseMarkdown(text); + if (isTemplate(text)) { + await events.dispatchEvent("page:indexTemplate", { + name, + tree: parsed, + }); + } else { + await events.dispatchEvent("page:index", { + name, + tree: parsed, + }); + } +} + export async function parseIndexTextRepublish({ name, text }: IndexEvent) { if (await system.getMode() === "ro") { console.info("Not reindexing", name, "because we're in read-only mode");