Skip to content

Commit 1f3c944

Browse files
authored
Merge branch 'main' into docs/backlog-weft-inspired-items
2 parents 0d13263 + 5c986f4 commit 1f3c944

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

.claude/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"env": {
3+
"CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING": "1"
4+
},
25
"hooks": {
36
"PreToolUse": [
47
{

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ coverage/
77
.env
88
grammars/*.wasm
99
.claude/session-edits.log
10+
.claude/worktrees/
1011
generated/DEPENDENCIES.md
1112
generated/DEPENDENCIES.json
1213
artifacts/

crates/codegraph-core/src/structure.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,25 @@ fn compute_file_metrics(
589589
}
590590
}
591591

592+
// Batch-load import counts per file from DB (distinct imported files,
593+
// matching the fast-path semantics in update_changed_file_metrics)
594+
let mut import_counts: HashMap<String, i64> = HashMap::new();
595+
if let Ok(mut stmt) = tx.prepare(
596+
"SELECT n1.file, COUNT(DISTINCT n2.file) FROM edges e \
597+
JOIN nodes n1 ON e.source_id = n1.id \
598+
JOIN nodes n2 ON e.target_id = n2.id \
599+
WHERE e.kind = 'imports' \
600+
GROUP BY n1.file",
601+
) {
602+
if let Ok(rows) = stmt.query_map([], |row| {
603+
Ok((row.get::<_, String>(0)?, row.get::<_, i64>(1)?))
604+
}) {
605+
for row in rows.flatten() {
606+
import_counts.insert(row.0, row.1);
607+
}
608+
}
609+
}
610+
592611
{
593612
let mut upsert = match tx.prepare(
594613
"INSERT OR REPLACE INTO node_metrics \
@@ -607,7 +626,7 @@ fn compute_file_metrics(
607626

608627
let line_count = line_count_map.get(rel_path).copied().unwrap_or(0);
609628
let symbol_count = symbol_counts.get(rel_path).copied().unwrap_or(0);
610-
let import_count = symbols.imports.len() as i64;
629+
let import_count = import_counts.get(rel_path).copied().unwrap_or(0);
611630
let export_count = symbols.exports.len() as i64;
612631
let fan_in = fan_in_map.get(rel_path).copied().unwrap_or(0);
613632
let fan_out = fan_out_map.get(rel_path).copied().unwrap_or(0);

src/features/structure.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ function computeFileMetrics(
166166
fanOutMap: Map<string, number>,
167167
): void {
168168
db.transaction(() => {
169+
// Batch-load import counts per file (distinct imported files,
170+
// matching the fast-path semantics in updateChangedFileMetrics).
171+
// Runs inside the transaction for parity with the Rust path.
172+
const importCountMap = new Map<string, number>();
173+
for (const row of db
174+
.prepare(
175+
`SELECT n1.file AS src, COUNT(DISTINCT n2.file) AS cnt FROM edges e
176+
JOIN nodes n1 ON e.source_id = n1.id
177+
JOIN nodes n2 ON e.target_id = n2.id
178+
WHERE e.kind = 'imports'
179+
GROUP BY n1.file`,
180+
)
181+
.all() as { src: string; cnt: number }[]) {
182+
importCountMap.set(row.src, row.cnt);
183+
}
184+
169185
for (const [relPath, symbols] of fileSymbols) {
170186
const fileRow = getNodeIdStmt.get(relPath, 'file', relPath, 0);
171187
if (!fileRow) continue;
@@ -180,7 +196,7 @@ function computeFileMetrics(
180196
symbolCount++;
181197
}
182198
}
183-
const importCount = symbols.imports.length;
199+
const importCount = importCountMap.get(relPath) || 0;
184200
const exportCount = symbols.exports.length;
185201
const fanIn = fanInMap.get(relPath) || 0;
186202
const fanOut = fanOutMap.get(relPath) || 0;

0 commit comments

Comments
 (0)