From d5e2ba08736cdc1a2eeb7ea3ccf96e76ae99851c Mon Sep 17 00:00:00 2001 From: Alexander Simoes Date: Thu, 2 Jan 2025 21:08:02 -0500 Subject: [PATCH] fixes bug of zero pageviews in january --- app/[locale]/profile/person/[id]/page.jsx | 5 ++++- cache-handler.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/[locale]/profile/person/[id]/page.jsx b/app/[locale]/profile/person/[id]/page.jsx index ceaf0e9..992fb3b 100644 --- a/app/[locale]/profile/person/[id]/page.jsx +++ b/app/[locale]/profile/person/[id]/page.jsx @@ -58,7 +58,10 @@ async function getWikiPageViews(personName) { const wikiSlug = personName.replace(/ /g, "_"); const dateobj = new Date(); const year = dateobj.getFullYear(); - const month = `${dateobj.getMonth()}`.replace(/(^|\D)(\d)(?!\d)/g, "$10$2"); + const month = `${dateobj.getMonth() + 1}`.replace( + /(^|\D)(\d)(?!\d)/g, + "$10$2" + ); const apiUrl = `https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/${wikiSlug}/monthly/20110101/${year}${month}01`; try { const res = await fetch(apiUrl, { diff --git a/cache-handler.js b/cache-handler.js index 97b4103..ef24c64 100644 --- a/cache-handler.js +++ b/cache-handler.js @@ -18,6 +18,7 @@ const storage = new Storage({ retryOptions: { autoRetry: true, maxRetries: 3, + retryDelayMultiplier: 2, }, }); @@ -147,6 +148,9 @@ CacheHandler.onCreation(() => { return { handlers: [handler], + ttl: { + defaultStaleAge: 3600, + }, }; });