Skip to content

Commit b60fbb7

Browse files
committed
fix: address review feedback — version check, Set mutation, barrel edge duplication (#634)
- Move _versionWarned flag outside mismatch conditional to avoid redundant build_meta queries when versions match. - Wrap SUPPORTED_EXTENSIONS in new Set() to avoid mutating the sibling module's export. - Delete outgoing edges for barrel-only files before re-adding them to fileSymbols during incremental builds, preventing duplicate reexport edges.
1 parent 8e43e43 commit b60fbb7

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/db/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export function openReadonlyOrFail(customPath?: string): BetterSqlite3Database {
221221
) => BetterSqlite3Database
222222
)(dbPath, { readonly: true });
223223

224-
// Warn once if the DB was built with a different codegraph version
224+
// Warn once per process if the DB was built with a different codegraph version
225225
if (!_versionWarned) {
226226
try {
227227
const row = db
@@ -233,11 +233,11 @@ export function openReadonlyOrFail(customPath?: string): BetterSqlite3Database {
233233
warn(
234234
`DB was built with codegraph v${buildVersion}, running v${currentVersion}. Consider: codegraph build --no-incremental`,
235235
);
236-
_versionWarned = true;
237236
}
238237
} catch {
239238
// build_meta table may not exist in older DBs — silently ignore
240239
}
240+
_versionWarned = true;
241241
}
242242

243243
return db;

src/domain/graph/builder/stages/resolve-imports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,19 @@ export async function resolveImports(ctx: PipelineContext): Promise<void> {
4646
JOIN nodes n1 ON e.source_id = n1.id
4747
WHERE e.kind = 'reexports' AND n1.kind = 'file'`)
4848
.all() as Array<{ file: string }>;
49+
// Barrel-only files will have edges re-created by buildEdges; delete
50+
// their outgoing edges first to prevent duplicates during incremental builds.
51+
const deleteOutgoingEdges = db.prepare(
52+
'DELETE FROM edges WHERE source_id IN (SELECT id FROM nodes WHERE file = ?)',
53+
);
4954
for (const { file: relPath } of barrelCandidates) {
5055
if (fileSymbols.has(relPath)) continue;
5156
const absPath = path.join(rootDir, relPath);
5257
try {
5358
const symbols = await parseFilesAuto([absPath], rootDir, engineOpts);
5459
const fileSym = symbols.get(relPath);
5560
if (fileSym) {
61+
deleteOutgoingEdges.run(relPath);
5662
fileSymbols.set(relPath, fileSym);
5763
ctx.barrelOnlyFiles.add(relPath);
5864
const reexports = fileSym.imports.filter((imp: Import) => imp.reexport);

src/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const IGNORE_DIRS: ArrayCompatSet<string> = withArrayCompat(
3636
]),
3737
);
3838

39-
export const EXTENSIONS: ArrayCompatSet<string> = withArrayCompat(SUPPORTED_EXTENSIONS);
39+
export const EXTENSIONS: ArrayCompatSet<string> = withArrayCompat(new Set(SUPPORTED_EXTENSIONS));
4040

4141
export function shouldIgnore(dirName: string): boolean {
4242
return IGNORE_DIRS.has(dirName) || dirName.startsWith('.');

0 commit comments

Comments
 (0)