* Get a node by ID
(id: string)
| 756 | * Get a node by ID |
| 757 | */ |
| 758 | getNodeById(id: string): Node | null { |
| 759 | // Check cache first |
| 760 | if (this.nodeCache.has(id)) { |
| 761 | const cached = this.nodeCache.get(id)!; |
| 762 | // Move to end to implement LRU (delete and re-add) |
| 763 | this.nodeCache.delete(id); |
| 764 | this.nodeCache.set(id, cached); |
| 765 | return cached; |
| 766 | } |
| 767 | |
| 768 | if (!this.stmts.getNodeById) { |
| 769 | this.stmts.getNodeById = this.db.prepare('SELECT * FROM nodes WHERE id = ?'); |
| 770 | } |
| 771 | const row = this.stmts.getNodeById.get(id) as NodeRow | undefined; |
| 772 | if (!row) { |
| 773 | return null; |
| 774 | } |
| 775 | |
| 776 | const node = rowToNode(row); |
| 777 | this.cacheNode(node); |
| 778 | return node; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Batch lookup: fetch many nodes by ID in a single SQL round-trip. |