refactor: reactions grouping and other fixes

This commit is contained in:
2024-01-09 16:40:31 +00:00
parent 4455651d47
commit 80fa5a132b
58 changed files with 344 additions and 501 deletions

View File

@ -20,7 +20,7 @@ export interface FeedCacheEvents {
export abstract class FeedCache<TCached> extends EventEmitter<FeedCacheEvents> {
readonly name: string;
#snapshot: Array<TCached> = [];
#log: ReturnType<typeof debug>;
protected log: ReturnType<typeof debug>;
#hits = 0;
#miss = 0;
protected table?: DexieTableLike<TCached>;
@ -31,9 +31,9 @@ export abstract class FeedCache<TCached> extends EventEmitter<FeedCacheEvents> {
super();
this.name = name;
this.table = table;
this.#log = debug(name);
this.log = debug(name);
setInterval(() => {
this.#log(
this.log(
"%d loaded, %d on-disk, %d hooks, %d% hit",
this.cache.size,
this.onTable.size,
@ -55,21 +55,15 @@ export abstract class FeedCache<TCached> extends EventEmitter<FeedCacheEvents> {
}
hook(fn: HookFn, key: string | undefined) {
if (key) {
const handle = (keys: Array<string>) => {
if (keys.includes(key)) {
fn();
}
};
this.on("change", handle);
return () => this.off("change", handle);
}
return () => {
// noop
const handle = (keys: Array<string>) => {
if (!key || keys.includes(key)) {
fn();
}
};
this.on("change", handle);
return () => this.off("change", handle);
}
keysOnTable() {
return [...this.onTable];
}
@ -161,7 +155,7 @@ export abstract class FeedCache<TCached> extends EventEmitter<FeedCacheEvents> {
}
return "no_change";
})();
this.#log("Updating %s %s %o", k, updateType, m);
this.log("Updating %s %s %o", k, updateType, m);
if (updateType !== "no_change") {
const updated = {
...existing,
@ -193,7 +187,7 @@ export abstract class FeedCache<TCached> extends EventEmitter<FeedCacheEvents> {
"change",
fromCache.map(a => this.key(a)),
);
this.#log(`Loaded %d/%d in %d ms`, fromCache.length, keys.length, (unixNowMs() - start).toLocaleString());
this.log(`Loaded %d/%d in %d ms`, fromCache.length, keys.length, (unixNowMs() - start).toLocaleString());
return mapped.filter(a => !a.has).map(a => a.key);
}

View File

@ -136,7 +136,6 @@ export class LNURL {
const rsp = await fetch(`${baseUrl}?${queryJoined}`);
if (rsp.ok) {
const data: LNURLInvoice = await rsp.json();
console.debug("[LNURL]: ", data);
if (data.status === "ERROR") {
throw new Error(data.reason);
} else {