Iris nip-05 registration #638

Merged
Kieran merged 7 commits from mmalmi/snort:main into main 2023-10-04 10:44:26 +00:00
Showing only changes of commit e191528c4c - Show all commits

View File

@ -12,7 +12,7 @@ export interface KeyedHookFilter {
/** /**
* Dexie backed generic hookable store * Dexie backed generic hookable store
*/ */
export abstract class FeedCache<TCached> { export abstract class FeedCache<TCached> {
#name: string; #name: string;
#hooks: Array<KeyedHookFilter> = []; #hooks: Array<KeyedHookFilter> = [];
#snapshot: Array<TCached> = []; #snapshot: Array<TCached> = [];
@ -109,16 +109,24 @@ export abstract class FeedCache<TCached> {
const k = this.key(obj); const k = this.key(obj);
this.cache.set(k, obj); this.cache.set(k, obj);
if (this.table) { if (this.table) {
await this.table.put(obj); try {
this.onTable.add(k); await this.table.put(obj);
this.onTable.add(k);
} catch (e) {
console.error(e);
}
} }
this.notifyChange([k]); this.notifyChange([k]);
} }
async bulkSet(obj: Array<TCached> | Readonly<Array<TCached>>) { async bulkSet(obj: Array<TCached> | Readonly<Array<TCached>>) {
if (this.table) { if (this.table) {
await this.table.bulkPut(obj); try {
obj.forEach(a => this.onTable.add(this.key(a))); await this.table.bulkPut(obj);
obj.forEach(a => this.onTable.add(this.key(a)));
} catch (e) {
console.error(e);
}
} }
obj.forEach(v => this.cache.set(this.key(v), v)); obj.forEach(v => this.cache.set(this.key(v), v));
this.notifyChange(obj.map(a => this.key(a))); this.notifyChange(obj.map(a => this.key(a)));