Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pages/SettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export default function SettingsPage() {
}

const handleClear = async () => {
await cacheClear()
setCleared(true)
setTimeout(() => setCleared(false), 2000)
const success = await cacheClear()
if (success) {
setCleared(true)
setTimeout(() => setCleared(false), 2000)
}
}

const rateColor = rateLimit
Expand Down
50 changes: 42 additions & 8 deletions src/services/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@ export async function cacheGet(key) {
try {
const db = await openDB()
return new Promise(res => {
const req = db.transaction(STORE, 'readonly').objectStore(STORE).get(key)
const tx = db.transaction(STORE, 'readonly')
const req = tx.objectStore(STORE).get(key)
let value = null
req.onsuccess = () => {
const r = req.result
if (!r || Date.now() - r.ts > TTL_MS) return res(null)
res(r.v)
if (r && Date.now() - r.ts <= TTL_MS) {
value = r.v
}
}
tx.oncomplete = () => {
db.close()
res(value)
}
tx.onerror = () => {
db.close()
res(null)
}
tx.onabort = () => {
db.close()
res(null)
}
req.onerror = () => res(null)
})
} catch { return null }
}
Expand All @@ -33,8 +47,18 @@ export async function cacheSet(key, value) {
return new Promise(res => {
const tx = db.transaction(STORE, 'readwrite')
tx.objectStore(STORE).put({ k: key, v: value, ts: Date.now() })
tx.oncomplete = () => res(true)
tx.onerror = () => res(false)
tx.oncomplete = () => {
db.close()
res(true)
}
tx.onerror = () => {
db.close()
res(false)
}
tx.onabort = () => {
db.close()
res(false)
}
})
} catch { return false }
}
Expand All @@ -45,8 +69,18 @@ export async function cacheClear() {
return new Promise(res => {
const tx = db.transaction(STORE, 'readwrite')
tx.objectStore(STORE).clear()
tx.oncomplete = () => res(true)
tx.onerror = () => res(false)
tx.oncomplete = () => {
db.close()
res(true)
}
tx.onerror = () => {
db.close()
res(false)
}
tx.onabort = () => {
db.close()
res(false)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
})
} catch { return false }
}
Expand Down
Loading