From d1a827aa4a51eadb6206c00a1633ac49084e00ae Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 23 Jul 2024 13:12:02 +0200 Subject: [PATCH] Attempt to fix issue where pages would randomly disappear from the index I suspect this is due to event triggering order (where clearing happened at the same time as adding new entries), this should fix that. --- plugs/index/attachment.ts | 1 + plugs/index/command.ts | 4 ++++ plugs/index/index.plug.yaml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugs/index/attachment.ts b/plugs/index/attachment.ts index e88583c6..ebf53e94 100644 --- a/plugs/index/attachment.ts +++ b/plugs/index/attachment.ts @@ -2,6 +2,7 @@ import { space, system } from "$sb/syscalls.ts"; import { AttachmentMeta } from "$sb/types.ts"; import { indexObjects } from "./api.ts"; +// Note: clearFileIndex is not called but since this is the only attachmet:index listener, this should be fine (famous last words) export async function indexAttachment(name: string) { if (await system.getMode() === "ro") { return; diff --git a/plugs/index/command.ts b/plugs/index/command.ts index 4aac2520..536774d5 100644 --- a/plugs/index/command.ts +++ b/plugs/index/command.ts @@ -4,6 +4,7 @@ import { isTemplate } from "$lib/cheap_yaml.ts"; import { sleep } from "$lib/async.ts"; import { plugPrefix } from "$common/spaces/constants.ts"; import { indexAttachment } from "./attachment.ts"; +import { clearFileIndex } from "./api.ts"; export async function reindexCommand() { await editor.flashNotification("Performing full page reindex..."); @@ -75,6 +76,9 @@ export async function parseIndexTextRepublish({ name, text }: IndexEvent) { } const parsed = await markdown.parseMarkdown(text); + // First clear the old file index entries + await clearFileIndex(name); + if (isTemplate(text)) { // console.log("Indexing", name, "as template"); await events.dispatchEvent("page:indexTemplate", { diff --git a/plugs/index/index.plug.yaml b/plugs/index/index.plug.yaml index d827df32..18532d42 100644 --- a/plugs/index/index.plug.yaml +++ b/plugs/index/index.plug.yaml @@ -39,7 +39,6 @@ functions: env: server events: - file:deleted - - file:changed parseIndexTextRepublish: path: "./command.ts:parseIndexTextRepublish" @@ -52,6 +51,7 @@ functions: command: name: "Space: Reindex" requireMode: rw + processIndexQueue: path: ./command.ts:processIndexQueue mqSubscriptions: