浏览代码

Fix UNIQUE constraint crash on large C/C++ projects

Node insertion used plain INSERT which crashes on duplicate IDs.
In large C/C++ projects, tree-sitter can produce duplicate nodes for
the same symbol (e.g. typedef struct where both struct_specifier and
type_definition resolve to the same name/kind/line, or multiple
anonymous constructs on the same line).

- Change nodes INSERT to INSERT OR REPLACE (idempotent, same data)
- Change edges INSERT to INSERT OR IGNORE (skip duplicate edges)

The node ID is sha256(filePath:kind:name:line) which already uses full
relative paths, so cross-directory collisions are not the issue.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Colby McHenry 4 月之前
父节点
当前提交
c3cf891bf4
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      src/db/queries.ts

+ 2 - 2
src/db/queries.ts

@@ -185,7 +185,7 @@ export class QueryBuilder {
   insertNode(node: Node): void {
     if (!this.stmts.insertNode) {
       this.stmts.insertNode = this.db.prepare(`
-        INSERT INTO nodes (
+        INSERT OR REPLACE INTO nodes (
           id, kind, name, qualified_name, file_path, language,
           start_line, end_line, start_column, end_column,
           docstring, signature, visibility,
@@ -627,7 +627,7 @@ export class QueryBuilder {
   insertEdge(edge: Edge): void {
     if (!this.stmts.insertEdge) {
       this.stmts.insertEdge = this.db.prepare(`
-        INSERT INTO edges (source, target, kind, metadata, line, col)
+        INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col)
         VALUES (@source, @target, @kind, @metadata, @line, @col)
       `);
     }