Cache all the things

This commit is contained in:
2023-09-05 14:57:50 +01:00
parent 5521f685fc
commit b1459d0f49
49 changed files with 805 additions and 243 deletions

View File

@ -15,7 +15,7 @@ export interface KeyedHookFilter {
export abstract class FeedCache<TCached> {
#name: string;
#hooks: Array<KeyedHookFilter> = [];
#snapshot: Readonly<Array<TCached>> = [];
#snapshot: Array<TCached> = [];
#changed = true;
#hits = 0;
#miss = 0;
@ -37,6 +37,10 @@ export abstract class FeedCache<TCached> {
}, 30_000);
}
get name() {
return this.#name;
}
async preload() {
const keys = (await this.table?.toCollection().primaryKeys()) ?? [];
this.onTable = new Set<string>(keys.map(a => a as string));
@ -111,7 +115,7 @@ export abstract class FeedCache<TCached> {
this.notifyChange([k]);
}
async bulkSet(obj: Array<TCached>) {
async bulkSet(obj: Array<TCached> | Readonly<Array<TCached>>) {
if (this.table) {
await this.table.bulkPut(obj);
obj.forEach(a => this.onTable.add(this.key(a)));