MCPcopy
hub / github.com/promptfoo/promptfoo / getTotalResultRowCount

Function getTotalResultRowCount

src/models/evalPerformance.ts:73–101  ·  view source on GitHub ↗
(evalId: string)

Source from the content-addressed store, hash-verified

71 * Use this for progress tracking when iterating over all results (e.g., sharing).
72 */
73export 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
103export function clearCountCache(evalId?: string) {
104 if (evalId) {

Callers 3

Calls 3

getDbFunction · 0.90
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…