From 91adaa376d382d596365b7bfdb831ae575774abb Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sun, 31 Mar 2024 19:08:55 -0500 Subject: [PATCH] fix: reduce cache time (#36) --- src/lib/fetch-npm.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/fetch-npm.ts b/src/lib/fetch-npm.ts index eee7cdc..18fc0ef 100644 --- a/src/lib/fetch-npm.ts +++ b/src/lib/fetch-npm.ts @@ -54,11 +54,7 @@ async function getAllTime(pkg: string): Promise { const url = `https://api.npmjs.org/downloads/range/${start.format( "YYYY-MM-DD", )}:${end.format("YYYY-MM-DD")}/${pkg}`; - const res = await get( - url, - // if recent 18 months, cache for 1 hour - !start.isAfter(now.subtract(18, "month")), - ); + const res = await get(url); downloads += res.downloads.reduce((sum, d) => sum + d.downloads, 0); start = end; end = start.add(18, "month"); @@ -119,10 +115,10 @@ export async function fetchNpmPackage( }; } -async function get(url: string, longCache = true) { +async function get(url: string) { const res = await fetch(url, { next: { - revalidate: longCache ? 86_400 : 3_600, + revalidate: 3_600, tags: ["npm"], }, });