use readPageWithMeta syscall to reduce indexing cost

This commit is contained in:
Zef Hemel
2026-01-08 14:06:58 +01:00
parent dc21c5f6aa
commit ff60237d95
3 changed files with 6 additions and 5 deletions
+2
View File
@@ -1,9 +1,11 @@
import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree";
import type { EventSubscriptionDef } from "./manifest.ts";
import type { PageMeta } from "@silverbulletmd/silverbullet/type/index";
export type IndexTreeEvent = {
name: string;
tree: ParseTree;
meta: PageMeta;
text: string;
};
+2 -4
View File
@@ -5,7 +5,6 @@ import type {
import { extractFrontMatter, type FrontMatter } from "./frontmatter.ts";
import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree";
import type { IndexTreeEvent } from "@silverbulletmd/silverbullet/type/event";
import { space } from "@silverbulletmd/silverbullet/syscalls";
import { indexObjects } from "./api.ts";
import { indexPage as pageIndexPage } from "./page.ts";
import { indexData } from "./data.ts";
@@ -38,15 +37,14 @@ const allIndexers: IndexerFunction[] = [
indexTags,
];
export async function indexPage({ name, tree, text }: IndexTreeEvent) {
const pageMeta = await space.getPageMeta(name);
export async function indexPage({ name, tree, meta, text }: IndexTreeEvent) {
const frontmatter = extractFrontMatter(tree);
// console.log("Now going to index page", name);
// Index the page
const index = await Promise.all(allIndexers.map((indexer) => {
return indexer(pageMeta, frontmatter, tree, text);
return indexer(meta, frontmatter, tree, text);
}));
// console.log("Found these objects", index.flat());
+2 -1
View File
@@ -79,12 +79,13 @@ async function indexFile(path: string) {
// Page
const name = path.slice(0, -3);
// Read and parse the file
const text = await space.readPage(name);
const { text, meta } = await space.readPageWithMeta(name);
const tree = await markdown.parseMarkdown(text);
// Emit the event which will be picked up by indexers
await events.dispatchEvent("page:index", {
name,
meta,
tree,
text,
} as IndexTreeEvent);