@@ -73,6 +73,7 @@ import {
7373import { isScopedCSSRequest } from './scoped-css' ;
7474import type { FileMetaResource } from './resource-types' ;
7575import type { VirtualNetwork } from './virtual-network' ;
76+ import type { RequestTimings } from './request-timings' ;
7677
7778export interface IndexedFile {
7879 type : 'file' ;
@@ -139,7 +140,8 @@ interface InstanceError extends Partial<
139140export type InstanceOrError = IndexedInstance | InstanceError ;
140141
141142type GetEntryOptions = WIPOptions ;
142- export type QueryOptions = WIPOptions & PrerenderedCardOptions ;
143+ export type QueryOptions = WIPOptions &
144+ PrerenderedCardOptions & { timings ?: RequestTimings } ;
143145
144146interface PrerenderedCardOptions {
145147 htmlFormat ?: PrerenderedHtmlFormat ;
@@ -197,8 +199,20 @@ export class IndexQueryEngine {
197199 return await query ( this . #dbAdapter, expression , coerceTypes ) ;
198200 }
199201
200- async #queryCards( query : CardExpression ) {
201- return this . #query( await this . makeExpression ( query ) ) ;
202+ // Split the two phases so the search-timing line can attribute the SQL
203+ // stage. `makeExpression` resolves the filter tree to SQL — that resolution
204+ // runs a `getDefinition` card-definition lookup per type/field (a cache
205+ // read, or a module prerender on a miss), so it can dominate a search whose
206+ // actual row fetch is tiny. `#query` is the DB round-trip itself. The data
207+ // and count queries run concurrently, so these accumulate into the
208+ // parallel-sum `busy` bucket rather than the wall-clock stages.
209+ async #queryCards( query : CardExpression , timings ?: RequestTimings ) {
210+ let expression = timings
211+ ? await timings . busyTime ( 'compile' , ( ) => this . makeExpression ( query ) )
212+ : await this . makeExpression ( query ) ;
213+ return timings
214+ ? await timings . busyTime ( 'sqlExec' , ( ) => this . #query( expression ) )
215+ : this . #query( expression ) ;
202216 }
203217
204218 async getInstance (
@@ -608,8 +622,8 @@ export class IndexQueryEngine {
608622 ] ;
609623
610624 let [ results , totalResults ] = await Promise . all ( [
611- this . #queryCards( query ) ,
612- this . #queryCards( queryCount ) ,
625+ this . #queryCards( query , opts . timings ) ,
626+ this . #queryCards( queryCount , opts . timings ) ,
613627 ] ) ;
614628
615629 return {
0 commit comments