Skip to content

Commit

Permalink
rocksdb: minor tweaks (#613)
Browse files Browse the repository at this point in the history
* drafts are writable

* session overwrite should emit events
  • Loading branch information
chm-diederichs committed Dec 12, 2024
1 parent f19c966 commit be54b69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class Hypercore extends EventEmitter {
}

_isWritable () {
if (this.draft) return true
return !this._readonly && !!(this.keyPair && this.keyPair.secretKey)
}

Expand Down
9 changes: 8 additions & 1 deletion lib/session-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,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,
Expand Down

0 comments on commit be54b69

Please sign in to comment.