Work on plug:run

This commit is contained in:
Zef Hemel
2023-08-11 20:37:13 +02:00
parent d4f7833f0d
commit 4dbbc31cb9
24 changed files with 174 additions and 104 deletions
+14 -20
View File
@@ -14,7 +14,8 @@ import { events, mq } from "$sb/plugos-syscall/mod.ts";
import { applyQuery } from "$sb/lib/query.ts";
import { invokeFunction } from "$sb/silverbullet-syscall/system.ts";
import type { Message } from "$sb/mq.ts";
import type { Message } from "$sb/types.ts";
import { sleep } from "../../common/async_util.ts";
// Key space:
// meta: => metaJson
@@ -83,14 +84,9 @@ export async function newPageCommand() {
}
export async function reindexCommand() {
await editor.flashNotification("Scheduling full reindex...");
console.log("Clearing page index...");
await index.clearPageIndex();
// Executed this way to not have to embed the search plug code here
await invokeFunction("client", "search.clearIndex");
const pages = await space.listPages();
await mq.batchSend("indexQueue", pages.map((page) => page.name));
await editor.flashNotification("Performing full page reindex...");
await reindexSpace();
await editor.flashNotification("Done with page index!");
}
// Completion
@@ -117,20 +113,18 @@ export async function reindexSpace() {
await index.clearPageIndex();
// Executed this way to not have to embed the search plug code here
await invokeFunction("client", "search.clearIndex");
console.log("Listing all pages");
const pages = await space.listPages();
let counter = 0;
for (const { name } of pages) {
counter++;
console.log(`Indexing page ${counter}/${pages.length}: ${name}`);
const text = await space.readPage(name);
const parsed = await markdown.parseMarkdown(text);
await events.dispatchEvent("page:index", {
name,
tree: parsed,
});
// Queue all page names to be indexed
await mq.batchSend("indexQueue", pages.map((page) => page.name));
// Now let's wait for the processing to finish
let queueStats = await mq.getQueueStats("indexQueue");
while (queueStats.queued > 0 || queueStats.processing > 0) {
sleep(1000);
queueStats = await mq.getQueueStats("indexQueue");
}
// And notify the user
console.log("Indexing completed!");
}
+19 -19
View File
@@ -10,7 +10,10 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
import { PageMeta } from "../../web/types.ts";
import { isFederationPath } from "$sb/lib/resolve.ts";
import { mq } from "$sb/plugos-syscall/mod.ts";
import { Message } from "$sb/mq.ts";
import { Message } from "$sb/types.ts";
import { sleep } from "../../common/async_util.ts";
const directiveUpdateQueueName = "directiveUpdateQueue";
export async function updateDirectivesOnPageCommand() {
// If `arg` is a string, it's triggered automatically via an event, not explicitly via a command
@@ -83,10 +86,10 @@ export async function updateDirectivesInSpaceCommand() {
await editor.flashNotification(
"Updating directives in entire space, this can take a while...",
);
// await updateDirectivesInSpace();
const pages = await space.listPages();
await updateDirectivesInSpace();
await mq.batchSend("directiveUpdateQueue", pages.map((page) => page.name));
// And notify the user
await editor.flashNotification("Updating of all directives completed!");
}
export async function processUpdateQueue(messages: Message[]) {
@@ -94,7 +97,7 @@ export async function processUpdateQueue(messages: Message[]) {
const pageName: string = message.body;
console.log("Updating directives in page", pageName);
await updateDirectivesForPage(pageName);
await mq.ack("directiveUpdateQueue", message.id);
await mq.ack(directiveUpdateQueueName, message.id);
}
}
@@ -144,20 +147,17 @@ async function findReplacements(
}
export async function updateDirectivesInSpace() {
const allPages = await space.listPages();
let counter = 0;
for (const page of allPages) {
counter++;
console.log(
`Updating directives in page [${counter}/${allPages.length}]`,
page.name,
);
try {
await updateDirectivesForPage(page.name);
} catch (e: any) {
console.error("Error while updating directives on page", page.name, e);
}
const pages = await space.listPages();
await mq.batchSend(directiveUpdateQueueName, pages.map((page) => page.name));
// Now let's wait for the processing to finish
let queueStats = await mq.getQueueStats(directiveUpdateQueueName);
while (queueStats.queued > 0 || queueStats.processing > 0) {
sleep(1000);
queueStats = await mq.getQueueStats(directiveUpdateQueueName);
}
console.log("Done updating directives in space!");
}
async function updateDirectivesForPage(
@@ -180,7 +180,7 @@ async function updateDirectivesForPage(
const newText = await updateDirectives(pageMeta, tree, currentText);
if (newText !== currentText) {
console.info("Content of page changed, saving.");
console.info("Content of page changed, saving", pageName);
await space.writePage(pageName, newText);
}
}
-1
View File
@@ -1,4 +1,3 @@
import { c } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/clike?external=@codemirror/language";
import { stemmer } from "https://esm.sh/porter-stemmer@0.9.1";
export type Document = {