* `compute()`'s answer, reused until the database changes (see * getChangeStamp), or null inside a transaction, where a rollback could * leave a stale answer under an unchanged stamp: the caller then reads the * database directly, as it did before the memo.
(key: string, compute: () => T)
| 647 | * database directly, as it did before the memo. |
| 648 | */ |
| 649 | private memoizedRead<T>(key: string, compute: () => T): T | null { |
| 650 | if (this.db.inTransaction !== false) { |
| 651 | this.readMemos.delete(key); |
| 652 | return null; |
| 653 | } |
| 654 | const stamp = this.getChangeStamp(); |
| 655 | const memo = this.readMemos.get(key); |
| 656 | if (memo?.stamp === stamp) return memo.value as T; |
| 657 | const value = compute(); |
| 658 | this.readMemos.set(key, { stamp, value }); |
| 659 | return value; |
| 660 | } |
| 661 | |
| 662 | private edgeKindStmt(sql: string): SqliteStatement { |
| 663 | let stmt = this.edgeKindStmts.get(sql); |
no test coverage detected