2024-02-09 04:00:45 +08:00
|
|
|
import { DataStore } from "$lib/data/datastore.ts";
|
|
|
|
import { System } from "$lib/plugos/system.ts";
|
2024-01-11 20:20:50 +08:00
|
|
|
|
|
|
|
const indexVersionKey = ["$indexVersion"];
|
|
|
|
|
|
|
|
// Bump this one every time a full reinxex is needed
|
2024-01-25 21:51:40 +08:00
|
|
|
const desiredIndexVersion = 4;
|
2024-01-11 20:20:50 +08: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-21 02:16:07 +08:00
|
|
|
await system.invokeFunction("index.reindexSpace", []);
|
2024-01-11 20:20:50 +08: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);
|
|
|
|
}
|