Skip to content

Commit 5d965c9

Browse files
committed
fix: hoist db.prepare() out of changedRanges loop in findAffectedFunctions (#558)
The prepared statement was being compiled on every iteration of the changedRanges loop. Hoisted to compile once before the loop.
1 parent 2d30003 commit 5d965c9

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/domain/analysis/impact.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,12 @@ function findAffectedFunctions(
338338
noTests: boolean,
339339
): NodeRow[] {
340340
const affectedFunctions: NodeRow[] = [];
341+
const defsStmt = db.prepare(
342+
`SELECT * FROM nodes WHERE file = ? AND kind IN ('function', 'method', 'class') ORDER BY line`,
343+
);
341344
for (const [file, ranges] of changedRanges) {
342345
if (noTests && isTestFile(file)) continue;
343-
const defs = db
344-
.prepare(
345-
`SELECT * FROM nodes WHERE file = ? AND kind IN ('function', 'method', 'class') ORDER BY line`,
346-
)
347-
.all(file) as NodeRow[];
346+
const defs = defsStmt.all(file) as NodeRow[];
348347
for (let i = 0; i < defs.length; i++) {
349348
const def = defs[i]!;
350349
const endLine = def.end_line || (defs[i + 1] ? defs[i + 1]!.line - 1 : 999999);

0 commit comments

Comments
 (0)