* Insert multiple nodes in a transaction
(nodes: Node[])
| 814 | * Insert multiple nodes in a transaction |
| 815 | */ |
| 816 | insertNodes(nodes: Node[]): void { |
| 817 | this.db.transaction(() => { |
| 818 | // Bulk path: same semantics as insertNode() per row (validation, cache |
| 819 | // invalidation, segment vocab), but bound as multi-row INSERTs — the |
| 820 | // per-.run() call overhead dominates the store phase on full indexes. |
| 821 | const rows: unknown[][] = []; |
| 822 | const segmentRows: unknown[][] = []; |
| 823 | for (const node of nodes) { |
| 824 | if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) { |
| 825 | console.error('[CodeGraph] Skipping node with missing required fields:', { |
| 826 | id: node.id, |
| 827 | kind: node.kind, |
| 828 | name: node.name, |
| 829 | filePath: node.filePath, |
| 830 | language: node.language, |
| 831 | }); |
| 832 | continue; |
| 833 | } |
| 834 | this.nodeCache.delete(node.id); |
| 835 | rows.push([ |
| 836 | node.id, |
| 837 | node.kind, |
| 838 | node.name, |
| 839 | node.qualifiedName ?? node.name, |
| 840 | node.filePath, |
| 841 | node.language, |
| 842 | node.startLine ?? 0, |
| 843 | node.endLine ?? 0, |
| 844 | node.startColumn ?? 0, |
| 845 | node.endColumn ?? 0, |
| 846 | node.docstring ?? null, |
| 847 | node.signature ?? null, |
| 848 | node.visibility ?? null, |
| 849 | node.isExported ? 1 : 0, |
| 850 | node.isAsync ? 1 : 0, |
| 851 | node.isStatic ? 1 : 0, |
| 852 | node.isAbstract ? 1 : 0, |
| 853 | node.decorators ? JSON.stringify(node.decorators) : null, |
| 854 | node.typeParameters ? JSON.stringify(node.typeParameters) : null, |
| 855 | node.returnType ?? null, |
| 856 | node.updatedAt ?? Date.now(), |
| 857 | ]); |
| 858 | if (this.isSegmentableKind(node.kind)) this.collectNameSegmentRows(node.name, segmentRows); |
| 859 | } |
| 860 | this.runBatched( |
| 861 | 'insertNodes', |
| 862 | `INSERT OR REPLACE INTO nodes ( |
| 863 | id, kind, name, qualified_name, file_path, language, |
| 864 | start_line, end_line, start_column, end_column, |
| 865 | docstring, signature, visibility, |
| 866 | is_exported, is_async, is_static, is_abstract, |
| 867 | decorators, type_parameters, return_type, updated_at |
| 868 | ) VALUES `, |
| 869 | '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', |
| 870 | rows |
| 871 | ); |
| 872 | this.runBatched( |
| 873 | 'insertNameSegments', |
no test coverage detected