(evalId: string)
| 71 | * Use this for progress tracking when iterating over all results (e.g., sharing). |
| 72 | */ |
| 73 | export async function getTotalResultRowCount(evalId: string): Promise<number> { |
| 74 | const cacheKey = `total:${evalId}`; |
| 75 | const cached = totalRowCountCache.get(cacheKey); |
| 76 | |
| 77 | if (cached && Date.now() - cached.timestamp < CACHE_TTL) { |
| 78 | logger.debug(`Using cached total row count for eval ${evalId}: ${cached.count}`); |
| 79 | return cached.count; |
| 80 | } |
| 81 | |
| 82 | const db = await getDb(); |
| 83 | const start = Date.now(); |
| 84 | |
| 85 | // Count all result rows - use this when iterating over all results |
| 86 | const result = await db |
| 87 | .select({ count: sql<number>`COUNT(*)` }) |
| 88 | .from(evalResultsTable) |
| 89 | .where(sql`eval_id = ${evalId}`) |
| 90 | .all(); |
| 91 | |
| 92 | const count = Number(result[0]?.count ?? 0); |
| 93 | const duration = Date.now() - start; |
| 94 | |
| 95 | logger.debug(`Total row count query for eval ${evalId}: ${count} in ${duration}ms`); |
| 96 | |
| 97 | // Cache the result |
| 98 | totalRowCountCache.set(cacheKey, { count, timestamp: Date.now() }); |
| 99 | |
| 100 | return count; |
| 101 | } |
| 102 | |
| 103 | export function clearCountCache(evalId?: string) { |
| 104 | if (evalId) { |
no test coverage detected
searching dependent graphs…