From 236e584055912abaab6226fbc6c9fb28046799a5 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs <45171645+chm-diederichs@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:29:49 +0100 Subject: [PATCH] rocksdb: minor tweaks (#613) * drafts are writable * session overwrite should emit events --- index.js | 1 + lib/session-state.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1d19ec70..da168f01 100644 --- a/index.js +++ b/index.js @@ -395,6 +395,7 @@ class Hypercore extends EventEmitter { } _isWritable () { + if (this.draft) return true return !this._readonly && !!(this.keyPair && this.keyPair.secretKey) } diff --git a/lib/session-state.js b/lib/session-state.js index b4adab87..da92dbc3 100644 --- a/lib/session-state.js +++ b/lib/session-state.js @@ -511,7 +511,14 @@ module.exports = class SessionState { await this.mutex.lock() try { - await this._overwrite(state, length, treeLength, null) + const origLength = this.tree.length + + const tree = await this._overwrite(state, length, treeLength, null) + + const bitfield = { start: treeLength, length: tree.length - treeLength, drop: false } + + if (treeLength < origLength) this.ontruncate(tree, treeLength, origLength) + if (treeLength < tree.length) this.onappend(tree, bitfield) return { length: this.tree.length,