From 692fe2ad9a49ef6ad367810343cb96fba39c4301 Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Mon, 15 Jun 2026 07:38:45 -0400 Subject: [PATCH] refactor(18): IN-01/IN-02 reuse fetched row for GET timezone fallback The GET /config/timezone handler SELECTed app_config then, on the unset path, called getHouseholdTimezone(db) which re-issued the identical SELECT before falling back (IN-01). The fallback decision also lived in two places (IN-02). Route the handler through the centralized resolveHouseholdTimezone(row?.value) added for WR-01: no redundant round-trip, single source for the D-06 policy. Behavior unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/api/src/routes/admin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/api/src/routes/admin.ts b/apps/api/src/routes/admin.ts index de49ceb..5f50ca5 100644 --- a/apps/api/src/routes/admin.ts +++ b/apps/api/src/routes/admin.ts @@ -27,7 +27,7 @@ import { eq, sql } from 'drizzle-orm'; import { db } from '../db/client.js'; import { users, memberCredentials, calendars, appConfig } from '../db/schema.js'; import { requireAdmin } from '../lib/requireAdmin.js'; -import { isValidIanaTimezone, getHouseholdTimezone } from '../lib/householdTimezone.js'; +import { isValidIanaTimezone, resolveHouseholdTimezone } from '../lib/householdTimezone.js'; import { validateEncryptAndStoreCredential, CredentialValidationError, @@ -205,9 +205,9 @@ adminRouter.get('/config/timezone', async (c) => { .limit(1); const isExplicitlySet = row?.value != null; - const timezone = isExplicitlySet - ? (row.value as string) - : await getHouseholdTimezone(db); + // IN-01/IN-02: reuse the row we just SELECTed and let the centralized accessor apply + // the D-06 fallback — no second app_config round-trip, single source for the policy. + const timezone = resolveHouseholdTimezone(row?.value ?? null); return c.json({ timezone, isExplicitlySet }); });