mirror of
https://github.com/outline/outline.git
synced 2026-12-03 10:00:13 +03:00
Adds a StorePersistence layer that caches a store's models in IndexedDB and hydrates them back at boot as stale data, revalidated by normal API traffic. Enabled for the policies store, scoped per team, so cached abilities are available immediately after a reload instead of every policy needing a forced refetch. - Persistence hooks in the base Store add/remove/clear methods, since add() updates existing models in place and map observation would miss those changes - Enabled from RootStore construction (team read from localStorage) and again after auth.info succeeds to cover the first session after login - Store.clear() wipes the persisted records, covering both logout paths - deleteAllDatabases() fallback removes the policies database on browsers without indexedDB.databases() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { flatten } from "es-toolkit/compat";
|
|
import stores from "~/stores";
|
|
import StorePersistence from "~/stores/base/StorePersistence";
|
|
import { flattenTree } from "@shared/utils/tree";
|
|
|
|
/**
|
|
* Delete all databases in the browser.
|
|
*
|
|
* @returns A promise that resolves when all databases have been deleted.
|
|
*/
|
|
export async function deleteAllDatabases() {
|
|
if (!window.indexedDB) {
|
|
return;
|
|
}
|
|
|
|
if (stores.auth.currentTeamId) {
|
|
window.indexedDB.deleteDatabase(
|
|
StorePersistence.databaseName("policies", stores.auth.currentTeamId)
|
|
);
|
|
}
|
|
|
|
if ("databases" in window.indexedDB) {
|
|
const databases = await window.indexedDB.databases();
|
|
|
|
for (const database of databases) {
|
|
if (database.name) {
|
|
window.indexedDB.deleteDatabase(database.name);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
// If the browser does not support listing databases, we need to manually delete as best we can
|
|
// by iterating over all known collections and documents.
|
|
await Promise.all(
|
|
stores.collections.orderedData.map(async (collection) => {
|
|
const nodes = flatten(collection.documents?.map(flattenTree));
|
|
|
|
return nodes.map(async (node) => {
|
|
window.indexedDB.deleteDatabase(`document.${node.id}`);
|
|
});
|
|
})
|
|
);
|
|
}
|