Skip to content

Commit

Permalink
Fix: Reset cache every hour needs own timer (#132)
Browse files Browse the repository at this point in the history
* Fix: Reset cache every hour needs own timer

* Add cypress retry

---------

Co-authored-by: Simon Heimler <[email protected]>
  • Loading branch information
Fannon and Simon Heimler authored Aug 25, 2024
1 parent 09ed00e commit 32e9531
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cypress.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
1 change: 1 addition & 0 deletions popup/js/model/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export async function setUserOptions(userOptions) {

// Invalidate caches
localStorage.removeItem('historyLastFetched')
localStorage.removeItem('historyLastReset')
localStorage.removeItem('history')

try {
Expand Down
16 changes: 8 additions & 8 deletions popup/js/model/searchData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32e9531

Please sign in to comment.