Stop recounting author stats constantly

This commit is contained in:
Alex Gleason
2024-05-24 20:16:51 -05:00
parent 6062378b7e
commit 69ff568214
3 changed files with 0 additions and 41 deletions

View File

@@ -1,7 +1,5 @@
import { Semaphore } from '@lambdalisue/async';
import { NostrEvent, NStore } from '@nostrify/nostrify';
import { Kysely, UpdateObject } from 'kysely';
import { LRUCache } from 'lru-cache';
import { SetRequired } from 'type-fest';
import { DittoTables } from '@/db/DittoTables.ts';
@@ -266,18 +264,3 @@ export async function refreshAuthorStats(
return stats;
}
const authorStatsSemaphore = new Semaphore(10);
const refreshedAuthors = new LRUCache<string, true>({ max: 1000 });
/** Calls `refreshAuthorStats` only once per author. */
export function refreshAuthorStatsDebounced(opts: RefreshAuthorStatsOpts): void {
if (refreshedAuthors.get(opts.pubkey)) {
return;
}
refreshedAuthors.set(opts.pubkey, true);
authorStatsSemaphore
.lock(() => refreshAuthorStats(opts).catch(() => {}));
}