66 findNodesByFile ,
77 openReadonlyOrFail ,
88} from '../../db/index.js' ;
9+ import { cachedStmt } from '../../db/repository/cached-stmt.js' ;
910import { loadConfig } from '../../infrastructure/config.js' ;
1011import { debug } from '../../infrastructure/logger.js' ;
1112import { isTestFile } from '../../infrastructure/test-filter.js' ;
@@ -15,11 +16,16 @@ import {
1516 extractSummary ,
1617} from '../../shared/file-utils.js' ;
1718import { paginateResult } from '../../shared/paginate.js' ;
18- import type { BetterSqlite3Database , NodeRow } from '../../types.js' ;
19+ import type { BetterSqlite3Database , NodeRow , StmtCache } from '../../types.js' ;
1920
2021/** Cache the schema probe for the `exported` column per db handle. */
2122const _hasExportedColCache : WeakMap < BetterSqlite3Database , boolean > = new WeakMap ( ) ;
2223
24+ const _exportedNodesStmtCache : StmtCache < NodeRow > = new WeakMap ( ) ;
25+ const _consumersStmtCache : StmtCache < { name : string ; file : string ; line : number } > = new WeakMap ( ) ;
26+ const _reexportsFromStmtCache : StmtCache < { file : string } > = new WeakMap ( ) ;
27+ const _reexportsToStmtCache : StmtCache < { file : string } > = new WeakMap ( ) ;
28+
2329export function exportsData (
2430 file : string ,
2531 customDbPath : string ,
@@ -128,18 +134,26 @@ function exportsFileImpl(
128134 _hasExportedColCache . set ( db , hasExportedCol ) ;
129135 }
130136
131- const exportedNodesStmt = db . prepare (
137+ const exportedNodesStmt = cachedStmt (
138+ _exportedNodesStmtCache ,
139+ db ,
132140 "SELECT * FROM nodes WHERE file = ? AND kind != 'file' AND exported = 1 ORDER BY line" ,
133141 ) ;
134- const consumersStmt = db . prepare (
142+ const consumersStmt = cachedStmt (
143+ _consumersStmtCache ,
144+ db ,
135145 `SELECT n.name, n.file, n.line FROM edges e JOIN nodes n ON e.source_id = n.id
136146 WHERE e.target_id = ? AND e.kind = 'calls'` ,
137147 ) ;
138- const reexportsFromStmt = db . prepare (
148+ const reexportsFromStmt = cachedStmt (
149+ _reexportsFromStmtCache ,
150+ db ,
139151 `SELECT DISTINCT n.file FROM edges e JOIN nodes n ON e.source_id = n.id
140152 WHERE e.target_id = ? AND e.kind = 'reexports'` ,
141153 ) ;
142- const reexportsToStmt = db . prepare (
154+ const reexportsToStmt = cachedStmt (
155+ _reexportsToStmtCache ,
156+ db ,
143157 `SELECT DISTINCT n.file FROM edges e JOIN nodes n ON e.target_id = n.id
144158 WHERE e.source_id = ? AND e.kind = 'reexports'` ,
145159 ) ;
0 commit comments