From bc8611ba7f4bf467db76194076b89e579ef09abc Mon Sep 17 00:00:00 2001 From: Bilthon Date: Tue, 2 Jun 2026 15:26:55 -0500 Subject: [PATCH] fix(daemon): include client identity in usage-summary cache key --- src/daemon/http/usage-summary.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/daemon/http/usage-summary.ts b/src/daemon/http/usage-summary.ts index ccd3023..5e164e6 100644 --- a/src/daemon/http/usage-summary.ts +++ b/src/daemon/http/usage-summary.ts @@ -129,9 +129,12 @@ export async function getUsageSummary( clients: ClientEntry[], tzOffsetMinutes: number, ): Promise { - // Cheap cache key: total row count + clients length + tz + // Cache key: total row count + per-client identity (id + ownerNpub) + tz. + // Including ownerNpub ensures a client assignment change invalidates the cache + // even though the row count doesn't change. const count = await driver.count(); - const cacheKey = `${count}:${clients.length}:${tzOffsetMinutes}`; + const clientIdentity = clients.map((c) => `${c.clientId}:${c.ownerNpub ?? ""}`).join(","); + const cacheKey = `${count}:${clientIdentity}:${tzOffsetMinutes}`; const now = Date.now(); if (