Auto reindexing on version upgrades

This commit is contained in:
Zef Hemel
2022-07-11 09:08:22 +02:00
parent ca86f75e16
commit c557253ad1
9 changed files with 75 additions and 5 deletions
+6
View File
@@ -41,6 +41,12 @@ functions:
command:
name: "Page: Delete"
editorInit:
path: "./editor.ts:editorInit"
env: client
events:
- plugs:loaded
# Backlinks
indexLinks:
path: "./page.ts:indexLinks"
+29
View File
@@ -0,0 +1,29 @@
import { get, set } from "@silverbulletmd/plugos-silverbullet-syscall";
import { flashNotification } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import {
getVersion,
invokeFunction,
} from "@silverbulletmd/plugos-silverbullet-syscall/system";
export async function editorInit() {
let currentVersion = await getVersion();
console.log("Running version check", currentVersion);
let lastVersion = await get("index", "$silverBulletVersion");
console.log("Last version", lastVersion);
if (lastVersion !== currentVersion) {
await flashNotification(
"Version update detected, going to reload plugs..."
);
await set("index", "$spaceIndexed", false);
await set("index", "$silverBulletVersion", currentVersion);
invokeFunction("client", "updatePlugsCommand");
} else {
let spaceIndexed = await get("index", "$spaceIndexed");
console.log("Space indexed", spaceIndexed);
if (!spaceIndexed) {
await invokeFunction("client", "reindexSpaceCommand");
// Resetting this, because part of the reindex will be to wipe this too
await set("index", "$silverBulletVersion", currentVersion);
}
}
}
+1
View File
@@ -189,6 +189,7 @@ async function getBackLinks(pageName: string): Promise<BackLink[]> {
export async function reindexCommand() {
await flashNotification("Reindexing...");
await invokeFunction("server", "reindexSpace");
await set("index", "$spaceIndexed", true);
await flashNotification("Reindexing done");
}