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>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
f03524f1c8
commit
c3cf891bf4
+2
-2
@@ -185,7 +185,7 @@ export class QueryBuilder {
|
|||||||
insertNode(node: Node): void {
|
insertNode(node: Node): void {
|
||||||
if (!this.stmts.insertNode) {
|
if (!this.stmts.insertNode) {
|
||||||
this.stmts.insertNode = this.db.prepare(`
|
this.stmts.insertNode = this.db.prepare(`
|
||||||
INSERT INTO nodes (
|
INSERT OR REPLACE INTO nodes (
|
||||||
id, kind, name, qualified_name, file_path, language,
|
id, kind, name, qualified_name, file_path, language,
|
||||||
start_line, end_line, start_column, end_column,
|
start_line, end_line, start_column, end_column,
|
||||||
docstring, signature, visibility,
|
docstring, signature, visibility,
|
||||||
@@ -627,7 +627,7 @@ export class QueryBuilder {
|
|||||||
insertEdge(edge: Edge): void {
|
insertEdge(edge: Edge): void {
|
||||||
if (!this.stmts.insertEdge) {
|
if (!this.stmts.insertEdge) {
|
||||||
this.stmts.insertEdge = this.db.prepare(`
|
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)
|
VALUES (@source, @target, @kind, @metadata, @line, @col)
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user