From 32e9531c1a94a0a55baebbcc16e5c73c9f5375fd Mon Sep 17 00:00:00 2001 From: Simon Heimler Date: Sun, 25 Aug 2024 14:54:26 +0200 Subject: [PATCH] Fix: Reset cache every hour needs own timer (#132) * Fix: Reset cache every hour needs own timer * Add cypress retry --------- Co-authored-by: Simon Heimler --- cypress.config.mjs | 6 +++++- popup/js/model/options.js | 1 + popup/js/model/searchData.js | 16 ++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cypress.config.mjs b/cypress.config.mjs index fbdd270..d796b7e 100644 --- a/cypress.config.mjs +++ b/cypress.config.mjs @@ -4,8 +4,12 @@ export default defineConfig({ viewportWidth: 500, viewportHeight: 600, video: false, - defaultCommandTimeout: 8000, // E2E Edge test is slow in CI/CD + defaultCommandTimeout: 4000, // E2E Edge test is slow in CI/CD e2e: { baseUrl: 'http://localhost:8080/popup', }, + retries: { + runMode: 2, + openMode: 0, + }, }) diff --git a/popup/js/model/options.js b/popup/js/model/options.js index 3dad6c9..2d81a07 100644 --- a/popup/js/model/options.js +++ b/popup/js/model/options.js @@ -388,6 +388,7 @@ export async function setUserOptions(userOptions) { // Invalidate caches localStorage.removeItem('historyLastFetched') + localStorage.removeItem('historyLastReset') localStorage.removeItem('history') try { diff --git a/popup/js/model/searchData.js b/popup/js/model/searchData.js index 1f1aafd..58ea803 100644 --- a/popup/js/model/searchData.js +++ b/popup/js/model/searchData.js @@ -66,16 +66,16 @@ export async function getSearchData() { } let startTime = Date.now() - 1000 * 60 * 60 * 24 * ext.opts.historyDaysAgo + let lastReset = parseInt(localStorage.getItem('historyLastReset') || 0) let lastFetch = parseInt(localStorage.getItem('historyLastFetched') || 0) - let historyC = [] - if (lastFetch) { - if (lastFetch < Date.now() - 1000 * 60 * 60) { - lastFetch = startTime // Reset cache every hour - } else if (lastFetch > startTime) { - historyC = JSON.parse(localStorage.getItem('history')) - startTime = lastFetch - } + if (lastReset < Date.now() - 1000 * 60 * 60) { + lastFetch = startTime // Reset cache every hour + localStorage.setItem('historyLastReset', Date.now()) + } + if (lastFetch && lastFetch > startTime) { + historyC = JSON.parse(localStorage.getItem('history')) + startTime = lastFetch } // Merge histories