* Get a node by ID
(id: string)
| 800 | * Get a node by ID |
| 801 | */ |
| 802 | getNodeById(id: string): Node | null { |
| 803 | // Check cache first |
| 804 | if (this.nodeCache.has(id)) { |
| 805 | const cached = this.nodeCache.get(id)!; |
| 806 | // Move to end to implement LRU (delete and re-add) |
| 807 | this.nodeCache.delete(id); |
| 808 | this.nodeCache.set(id, cached); |
| 809 | return cached; |
| 810 | } |
| 811 | |
| 812 | if (!this.stmts.getNodeById) { |
| 813 | this.stmts.getNodeById = this.db.prepare('SELECT * FROM nodes WHERE id = ?'); |
| 814 | } |
| 815 | const row = this.stmts.getNodeById.get(id) as NodeRow | undefined; |
| 816 | if (!row) { |
| 817 | return null; |
| 818 | } |
| 819 | |
| 820 | const node = rowToNode(row); |
| 821 | this.cacheNode(node); |
| 822 | return node; |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Batch lookup: fetch many nodes by ID in a single SQL round-trip. |