* Insert multiple nodes in a transaction
(nodes: Node[])
| 469 | * Insert multiple nodes in a transaction |
| 470 | */ |
| 471 | insertNodes(nodes: Node[]): void { |
| 472 | this.db.transaction(() => { |
| 473 | // Bulk path: same semantics as insertNode() per row (validation, cache |
| 474 | // invalidation, segment vocab), but bound as multi-row INSERTs — the |
| 475 | // per-.run() call overhead dominates the store phase on full indexes. |
| 476 | const rows: unknown[][] = []; |
| 477 | const segmentRows: unknown[][] = []; |
| 478 | for (const node of nodes) { |
| 479 | if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) { |
| 480 | console.error('[CodeGraph] Skipping node with missing required fields:', { |
| 481 | id: node.id, |
| 482 | kind: node.kind, |
| 483 | name: node.name, |
| 484 | filePath: node.filePath, |
| 485 | language: node.language, |
| 486 | }); |
| 487 | continue; |
| 488 | } |
| 489 | this.nodeCache.delete(node.id); |
| 490 | rows.push([ |
| 491 | node.id, |
| 492 | node.kind, |
| 493 | node.name, |
| 494 | node.qualifiedName ?? node.name, |
| 495 | node.filePath, |
| 496 | node.language, |
| 497 | node.startLine ?? 0, |
| 498 | node.endLine ?? 0, |
| 499 | node.startColumn ?? 0, |
| 500 | node.endColumn ?? 0, |
| 501 | node.docstring ?? null, |
| 502 | node.signature ?? null, |
| 503 | node.visibility ?? null, |
| 504 | node.isExported ? 1 : 0, |
| 505 | node.isAsync ? 1 : 0, |
| 506 | node.isStatic ? 1 : 0, |
| 507 | node.isAbstract ? 1 : 0, |
| 508 | node.decorators ? JSON.stringify(node.decorators) : null, |
| 509 | node.typeParameters ? JSON.stringify(node.typeParameters) : null, |
| 510 | node.returnType ?? null, |
| 511 | node.updatedAt ?? Date.now(), |
| 512 | ]); |
| 513 | if (this.isSegmentableKind(node.kind)) this.collectNameSegmentRows(node.name, segmentRows); |
| 514 | } |
| 515 | this.runBatched( |
| 516 | 'insertNodes', |
| 517 | `INSERT OR REPLACE INTO nodes ( |
| 518 | id, kind, name, qualified_name, file_path, language, |
| 519 | start_line, end_line, start_column, end_column, |
| 520 | docstring, signature, visibility, |
| 521 | is_exported, is_async, is_static, is_abstract, |
| 522 | decorators, type_parameters, return_type, updated_at |
| 523 | ) VALUES `, |
| 524 | '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', |
| 525 | rows |
| 526 | ); |
| 527 | this.runBatched( |
| 528 | 'insertNameSegments', |
no test coverage detected