Pre-index SETTINGS on full space reindex

pull/1027/head
Zef Hemel 2024-08-05 09:15:31 +02:00
parent 2b01130afd
commit 1bb096f503
1 changed files with 21 additions and 14 deletions

View File

@ -24,8 +24,12 @@ export async function reindexSpace(noClear = false) {
} }
// Load builtins // Load builtins
await system.invokeFunction("index.loadBuiltinsIntoIndex"); 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(); const files = await space.listFiles();
console.log("Queing", files.length, "pages to be indexed.");
// Queue all file names to be indexed // Queue all file names to be indexed
await mq.batchSend("indexQueue", files.map((file) => file.name)); await mq.batchSend("indexQueue", files.map((file) => file.name));
@ -49,26 +53,29 @@ export async function processIndexQueue(messages: MQMessage[]) {
console.log(`Indexing file ${name}`); console.log(`Indexing file ${name}`);
if (name.endsWith(".md")) { if (name.endsWith(".md")) {
name = name.slice(0, -3); name = name.slice(0, -3);
const text = await space.readPage(name); await indexPage(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,
});
}
} else { } else {
await indexAttachment(name); 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) { export async function parseIndexTextRepublish({ name, text }: IndexEvent) {
if (await system.getMode() === "ro") { if (await system.getMode() === "ro") {
console.info("Not reindexing", name, "because we're in read-only mode"); console.info("Not reindexing", name, "because we're in read-only mode");