1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2025-07-17 04:15:15 +02:00

chore(perf): save only failed days to KV storage

This commit is contained in:
Adam Janis
2020-11-11 23:39:54 +01:00
parent e85c5766a7
commit c3af9db11a
5 changed files with 63 additions and 45 deletions

View File

@ -4,7 +4,7 @@ export async function getMonitors() {
}
export async function getMonitorsHistory() {
const monitorsHistory = await listKV('h_', 600)
const monitorsHistory = await listKV('h_', 300)
return monitorsHistory.keys
}
@ -14,10 +14,12 @@ export async function getLastUpdate() {
export async function listKV(prefix = '', cacheTtl = false) {
const cacheKey = 'list_' + prefix + '_' + process.env.BUILD_ID
const cachedResponse = await getKV(cacheKey)
if (cacheTtl && cachedResponse) {
return JSON.parse(cachedResponse)
if (cacheTtl) {
const cachedResponse = await getKV(cacheKey)
if (cachedResponse) {
return JSON.parse(cachedResponse)
}
}
let list = []
@ -30,7 +32,7 @@ export async function listKV(prefix = '', cacheTtl = false) {
} while (!res.list_complete)
if (cacheTtl) {
await setKV(cacheKey, JSON.stringify({ keys: list }), null, 600)
await setKV(cacheKey, JSON.stringify({ keys: list }), null, cacheTtl)
}
return { keys: list }
}