2024-01-11 12:20:50 +00:00
|
|
|
import { DataStore } from "../plugos/lib/datastore.ts";
|
|
|
|
import { System } from "../plugos/system.ts";
|
|
|
|
|
|
|
|
const indexVersionKey = ["$indexVersion"];
|
|
|
|
|
|
|
|
// Bump this one every time a full reinxex is needed
|
2024-01-15 15:43:12 +00:00
|
|
|
const desiredIndexVersion = 3;
|
2024-01-11 12:20:50 +00:00
|
|
|
|
|
|
|
let indexOngoing = false;
|
|
|
|
|
|
|
|
export async function ensureSpaceIndex(ds: DataStore, system: System<any>) {
|
|
|
|
const currentIndexVersion = await ds.get(indexVersionKey);
|
|
|
|
|
|
|
|
console.info("Current space index version", currentIndexVersion);
|
|
|
|
|
|
|
|
if (currentIndexVersion !== desiredIndexVersion && !indexOngoing) {
|
|
|
|
console.info("Performing a full space reindex, this could take a while...");
|
|
|
|
indexOngoing = true;
|
2024-01-20 18:16:07 +00:00
|
|
|
await system.invokeFunction("index.reindexSpace", []);
|
2024-01-11 12:20:50 +00:00
|
|
|
console.info("Full space index complete.");
|
|
|
|
await markFullSpaceIndexComplete(ds);
|
|
|
|
indexOngoing = false;
|
|
|
|
} else {
|
|
|
|
console.info("Space index is up to date");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function markFullSpaceIndexComplete(ds: DataStore) {
|
|
|
|
await ds.set(indexVersionKey, desiredIndexVersion);
|
|
|
|
}
|