From b7b736b70742663cde4b9ab1c47c9d73a23f93bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Thu, 1 Feb 2024 16:38:30 +0100 Subject: [PATCH] [Fix] Caching in `downloadFile` (#3484) * Properly cache files downloaded with `downloadFile` * Bump up the max cache time to 30 days Somewhat of a band-aid fix; ideally we'd be smarter about this caching in the first place (for example only re-downloading if the user's hardware changed) --- src/backend/utils/inet/downloader/index.ts | 3 +-- src/backend/utils/systeminfo/gpu/pci_ids.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/inet/downloader/index.ts b/src/backend/utils/inet/downloader/index.ts index 9f58fd34ec..ad09753f94 100644 --- a/src/backend/utils/inet/downloader/index.ts +++ b/src/backend/utils/inet/downloader/index.ts @@ -51,8 +51,7 @@ async function downloadFile( if (options.maxCache && options.writeToFile) { const stats = await stat(options.writeToFile).catch(() => null) if (stats) { - if (stats.birthtime.valueOf() + options.maxCache * 1000 >= Date.now()) { - console.log('Returning cached value for', url) + if (stats.mtimeMs + options.maxCache * 1000 >= Date.now()) { switch (options.axiosConfig?.responseType) { case 'text': return readFile(options.writeToFile, 'utf-8') diff --git a/src/backend/utils/systeminfo/gpu/pci_ids.ts b/src/backend/utils/systeminfo/gpu/pci_ids.ts index 366056459b..b1c5e7c3eb 100644 --- a/src/backend/utils/systeminfo/gpu/pci_ids.ts +++ b/src/backend/utils/systeminfo/gpu/pci_ids.ts @@ -33,7 +33,7 @@ async function getPicIds(): Promise { responseType: 'text' }, writeToFile: path.join(toolsPath, 'pci.ids'), - maxCache: 7 * DAYS + maxCache: 30 * DAYS }).catch((error) => error as AxiosError) if (axios.isAxiosError(pciIdsFile)) return null