my own status page
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: less kv reads and writes

+16 -12
+5 -2
src/index.ts
··· 157 157 } 158 158 } 159 159 } else { 160 - // Service is up — clear failure counter 161 - await env.KV.delete(`triage:${svc.name}:failures`); 160 + // Service is up — clear failure counter (only if one exists, to avoid unnecessary KV delete ops) 161 + const failKey = `triage:${svc.name}:failures`; 162 + if (await env.KV.get(failKey)) { 163 + await env.KV.delete(failKey); 164 + } 162 165 163 166 // Auto-resolve active incidents 164 167 const active = await getActiveIncidentForService(env.DB, svc.name);
+11 -10
src/manifest.ts
··· 2 2 3 3 const MANIFEST_URL = "https://dots.dunkirk.sh/services.json"; 4 4 const KV_KEY = "services_manifest"; 5 - const TTL_SECONDS = 300; 6 5 7 6 export async function getManifest(env: Env): Promise<ServicesManifest> { 8 - const cached = await env.KV.get(KV_KEY, "json"); 9 - if (cached) return cached as ServicesManifest; 7 + const [res, existing] = await Promise.all([ 8 + fetch(MANIFEST_URL), 9 + env.KV.get(KV_KEY), 10 + ]); 11 + if (!res.ok) throw new Error(`Failed to fetch manifest: ${res.status}`); 10 12 11 - const res = await fetch(MANIFEST_URL); 12 - if (!res.ok) throw new Error(`Failed to fetch manifest: ${res.status}`); 13 + const serialized = JSON.stringify(await res.json()); 13 14 14 - const manifest: ServicesManifest = await res.json(); 15 - await env.KV.put(KV_KEY, JSON.stringify(manifest), { 16 - expirationTtl: TTL_SECONDS, 17 - }); 15 + // Only write to KV if the manifest changed 16 + if (serialized !== existing) { 17 + await env.KV.put(KV_KEY, serialized); 18 + } 18 19 19 - return manifest; 20 + return JSON.parse(serialized); 20 21 }