Comparing version 4.5.0 to 4.5.1
@@ -28,4 +28,4 @@ const Nanoiterator = require('nanoiterator') | ||
this._extension = (opts && opts.extension === false) ? null : db._extension | ||
this._extensionState = this._extension ? { active: false, missing: 0, head: 0 } : null | ||
this._onseq = (opts && opts.onseq) || null | ||
if (this._extension) this._onseq = sendExt(this, this._onseq) | ||
this._start = 0 | ||
@@ -48,3 +48,3 @@ this._end = 0 | ||
const self = this | ||
const opts = Object.assign(this._options || {}, { prefix: true, extension: false }) | ||
const opts = Object.assign(this._options || {}, { prefix: true, extension: false, onseq }) | ||
const prefix = this._db.get(this._prefix, opts, onnode) | ||
@@ -61,4 +61,27 @@ | ||
} | ||
function onseq (seq) { | ||
if (self._onseq) self._onseq(seq) | ||
const ext = self._extensionState | ||
if (!ext) return | ||
if (!ext.head) ext.head = seq | ||
if (!ext.active) { | ||
if (self._db.feed.bitfield.get(seq)) return | ||
ext.active = true | ||
} | ||
if (ext.missing > 0) ext.missing-- | ||
self._sendExtensionMessageMaybe(false) | ||
} | ||
} | ||
Iterator.prototype._sendExtensionMessageMaybe = function (checkpoint) { | ||
if (!this._extensionState.active || this._extensionState.missing > 0) return | ||
this._extensionState.missing = BATCH_SIZE | ||
this._extension.iterator(this._extensionState.head, this._prefix, this._flags, checkpoint ? this.checkpoint() : null) | ||
} | ||
Iterator.prototype._openCheckpoint = function (cb) { | ||
@@ -89,3 +112,2 @@ var ptr = 0 | ||
const s = this._stack[i] | ||
if (s.skip) continue | ||
varint.encode(s.i, buf, ptr) | ||
@@ -101,2 +123,7 @@ ptr += varint.encode.bytes | ||
Iterator.prototype._next = function (cb) { | ||
this._popStack(cb) | ||
if (this._extensionState && this._pending) this._sendExtensionMessageMaybe(true) | ||
} | ||
Iterator.prototype._popStack = function (cb) { | ||
var j | ||
@@ -145,2 +172,9 @@ | ||
if (this._onseq) this._onseq(seq) | ||
if (this._extensionState) { | ||
if (!this._extensionState.active) this._extensionState.active = !this._db.feed.bitfield.get(seq) | ||
if (this._extensionState.active && this._extensionState.missing > 0) this._extensionState.missing-- | ||
} | ||
if (!this._hadMissingBlock && this._db.feed.bitfield && !this._db.feed.bitfield.get(seq)) this._hadMissingBlock = true | ||
this._db.getBySeq(seq, this._options, onnode) | ||
@@ -198,23 +232,1 @@ | ||
} | ||
function sendExt (ite, onseq) { | ||
var headSeq = 0 | ||
var batch = 0 | ||
var started = false | ||
return function onseqwrap (seq) { | ||
if (!headSeq) headSeq = seq | ||
if (started || !ite._db.feed.bitfield.get(seq)) { | ||
started = true | ||
if (!batch) { | ||
ite._extension.iterator(headSeq, ite._prefix, ite._flags, headSeq === seq ? null : ite.checkpoint()) | ||
batch = BATCH_SIZE | ||
} | ||
batch-- | ||
if (!batch) started = false | ||
} | ||
if (onseq) onseq(seq) | ||
} | ||
} |
{ | ||
"name": "hypertrie", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "Distributed single writer key/value store", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126589
33
3916