Skip to content

Commit 0dc2814

Browse files
committed
fix(web): keep healthz cache small
1 parent 23827b2 commit 0dc2814

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

web/src/app/api/healthz/route.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { NextResponse } from 'next/server'
2-
import { getCachedAgents } from '@/server/agents-data'
2+
import { getAgentsCount } from '@/server/agents-data'
3+
4+
export const dynamic = 'force-dynamic'
35

46
export const GET = async () => {
57
try {
6-
// Warm the cache by fetching agents data
7-
// This ensures SEO-critical data is available immediately
8-
const agents = await getCachedAgents()
8+
// Lightweight check: just count agents to avoid caching large payloads
9+
const agentCount = await getAgentsCount()
910

1011
return NextResponse.json({
1112
status: 'ok',
12-
cached_agents: agents.length,
13-
timestamp: new Date().toISOString()
13+
agents: agentCount,
14+
timestamp: new Date().toISOString(),
1415
})
1516
} catch (error) {
1617
console.error('[Healthz] Failed to warm cache:', error)
@@ -19,7 +20,7 @@ export const GET = async () => {
1920
return NextResponse.json({
2021
status: 'ok',
2122
cache_warm: false,
22-
error: error instanceof Error ? error.message : 'Unknown error'
23+
error: error instanceof Error ? error.message : 'Unknown error',
2324
})
2425
}
2526
}

web/src/server/agents-data.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { unstable_cache } from 'next/cache'
44
import { sql, eq, and, gte } from 'drizzle-orm'
55
import { buildAgentsData } from './agents-transform'
66

7+
export const getAgentsCount = async (): Promise<number> => {
8+
const result = await db
9+
.select({ count: sql<number>`COUNT(*)` })
10+
.from(schema.agentConfig)
11+
12+
return result[0]?.count ?? 0
13+
}
14+
715
export interface AgentData {
816
id: string
917
name: string

0 commit comments

Comments
 (0)