More cards

This commit is contained in:
2026-10-19 18:52:49 -04:00
parent 716c9612cc
commit 0b9061372b
26 changed files with 549 additions and 201 deletions
+10 -1
View File
@@ -53,10 +53,19 @@ export class WikipediaEnrichment {
}
async get(pageId: number): Promise<PageEnrichment> {
return this.loadCached(pageId, false);
}
/** Bypass cached values when the result is being pinned into a newly minted block. */
async getFresh(pageId: number): Promise<PageEnrichment> {
return this.loadCached(pageId, true);
}
private async loadCached(pageId: number, fresh: boolean): Promise<PageEnrichment> {
if (!Number.isSafeInteger(pageId) || pageId <= 0) throw new RangeError('Invalid Wikipedia page ID');
const now = this.now();
const cached = this.cache.get(pageId);
if (cached && cached.expires > now.getTime() &&
if (!fresh && cached && cached.expires > now.getTime() &&
(!('value' in cached) || cached.value.pageviews.latestMonth === monthWindow(now)[5])) {
this.cache.delete(pageId);
this.cache.set(pageId, cached);