* Get a node by ID
(id: string)
| 413 | * Get a node by ID |
| 414 | */ |
| 415 | getNodeById(id: string): Node | null { |
| 416 | // Check cache first |
| 417 | if (this.nodeCache.has(id)) { |
| 418 | const cached = this.nodeCache.get(id)!; |
| 419 | // Move to end to implement LRU (delete and re-add) |
| 420 | this.nodeCache.delete(id); |
| 421 | this.nodeCache.set(id, cached); |
| 422 | return cached; |
| 423 | } |
| 424 | |
| 425 | if (!this.stmts.getNodeById) { |
| 426 | this.stmts.getNodeById = this.db.prepare('SELECT * FROM nodes WHERE id = ?'); |
| 427 | } |
| 428 | const row = this.stmts.getNodeById.get(id) as NodeRow | undefined; |
| 429 | if (!row) { |
| 430 | return null; |
| 431 | } |
| 432 | |
| 433 | const node = rowToNode(row); |
| 434 | this.cacheNode(node); |
| 435 | return node; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Batch lookup: fetch many nodes by ID in a single SQL round-trip. |