hypercore 10.24.2 → 10.24.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/batch.js +6 -4
- package/lib/core.js +28 -1
- package/package.json +1 -1
package/lib/batch.js
CHANGED
|
@@ -76,6 +76,7 @@ module.exports = class HypercoreBatch extends EventEmitter {
|
|
|
76
76
|
async update (opts) {
|
|
77
77
|
if (this.opened === false) await this.ready()
|
|
78
78
|
await this.session.update(opts)
|
|
79
|
+
await this._catchup()
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
setUserData (key, value, opts) {
|
|
@@ -271,14 +272,15 @@ module.exports = class HypercoreBatch extends EventEmitter {
|
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
274
|
|
|
274
|
-
const offset = this.
|
|
275
|
-
for (let i = 0; i < offset; i++) this._byteLength -= this._appends[i]
|
|
275
|
+
const offset = this.core.tree.length - this._sessionLength
|
|
276
|
+
for (let i = 0; i < offset; i++) this._byteLength -= this._appends[i].byteLength
|
|
277
|
+
|
|
278
|
+
await this.core.insertValuesUnsafe(this._appends.slice(0, offset), this._sessionLength, this._sessionByteLength, b.nodes)
|
|
276
279
|
|
|
277
280
|
this._sessionLength = this.session.length
|
|
278
281
|
this._sessionByteLength = this.session.byteLength
|
|
279
282
|
this._sessionBatch = this.session.createTreeBatch()
|
|
280
|
-
|
|
281
|
-
if (offset) this._appends = this._appends.slice(this._appends.length - offset)
|
|
283
|
+
this._appends = this._appends.slice(offset)
|
|
282
284
|
|
|
283
285
|
return true
|
|
284
286
|
}
|
package/lib/core.js
CHANGED
|
@@ -218,7 +218,7 @@ module.exports = class Core {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
async copyFrom (src, signature) {
|
|
221
|
-
this._mutex.lock()
|
|
221
|
+
await this._mutex.lock()
|
|
222
222
|
|
|
223
223
|
try {
|
|
224
224
|
let pos = src.bitfield.firstSet(0)
|
|
@@ -432,6 +432,33 @@ module.exports = class Core {
|
|
|
432
432
|
})
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
// assumes mutex is already acquried
|
|
436
|
+
async insertValuesUnsafe (values, offset, byteOffset, treeNodes) {
|
|
437
|
+
if (!values.length) return
|
|
438
|
+
|
|
439
|
+
const bitfield = {
|
|
440
|
+
drop: false,
|
|
441
|
+
start: offset,
|
|
442
|
+
end: offset + values.length
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
await this.blocks.putBatch(offset, values, byteOffset)
|
|
446
|
+
await this.oplog.append({
|
|
447
|
+
userData: null,
|
|
448
|
+
treeNodes,
|
|
449
|
+
treeUpgrade: null,
|
|
450
|
+
bitfield
|
|
451
|
+
}, false)
|
|
452
|
+
|
|
453
|
+
this.bitfield.setRange(bitfield.start, values.length, true)
|
|
454
|
+
for (const node of treeNodes) this.tree.unflushed.set(node.index, node)
|
|
455
|
+
|
|
456
|
+
const status = updateContig(this.header, bitfield, this.bitfield)
|
|
457
|
+
this.onupdate(status, bitfield, null, null)
|
|
458
|
+
|
|
459
|
+
if (this._shouldFlush()) await this._flushOplog()
|
|
460
|
+
}
|
|
461
|
+
|
|
435
462
|
async append (values, { lock, signature, keyPair = this.header.keyPair, preappend } = {}) {
|
|
436
463
|
if (lock) await this._mutex.lock()
|
|
437
464
|
|