Skip to content

Commit

Permalink
fixes bug of zero pageviews in january
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersimoes committed Jan 3, 2025
1 parent 9789b19 commit d5e2ba0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/[locale]/profile/person/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
4 changes: 4 additions & 0 deletions cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const storage = new Storage({
retryOptions: {
autoRetry: true,
maxRetries: 3,
retryDelayMultiplier: 2,
},
});

Expand Down Expand Up @@ -147,6 +148,9 @@ CacheHandler.onCreation(() => {

return {
handlers: [handler],
ttl: {
defaultStaleAge: 3600,
},
};
});

Expand Down

0 comments on commit d5e2ba0

Please sign in to comment.