Comparing version 2.19.2 to 2.19.3
46
index.js
@@ -39,3 +39,3 @@ const codecs = require('codecs') | ||
class KeyCache { | ||
class Cache { | ||
constructor () { | ||
@@ -70,4 +70,4 @@ this.keys = new Xache({ maxSize: 65536 }) | ||
class Pointers { | ||
constructor (buf) { | ||
this.levels = YoloIndex.decode(buf).levels.map(l => { | ||
constructor (decoded) { | ||
this.levels = decoded.levels.map(l => { | ||
const children = [] | ||
@@ -102,4 +102,8 @@ const keys = [] | ||
function inflate (buf) { | ||
return new Pointers(buf) | ||
function inflate (entry) { | ||
if (entry.inflated === null) { | ||
entry.inflated = YoloIndex.decode(entry.index) | ||
entry.index = null | ||
} | ||
return new Pointers(entry.inflated) | ||
} | ||
@@ -306,3 +310,3 @@ | ||
this.index = null | ||
this.indexBuffer = entry.index | ||
this.entry = entry | ||
this.key = entry.key | ||
@@ -320,4 +324,3 @@ this.value = entry.value | ||
if (this.index === null) { | ||
this.index = inflate(this.indexBuffer) | ||
this.indexBuffer = null | ||
this.index = inflate(this.entry) | ||
} | ||
@@ -338,4 +341,3 @@ | ||
if (this.index === null) { | ||
this.index = inflate(this.indexBuffer) | ||
this.indexBuffer = null | ||
this.index = inflate(this.entry) | ||
} | ||
@@ -349,3 +351,3 @@ const entry = this.index.get(offset) | ||
constructor (seq, tree, key, value, index) { | ||
super(seq, tree, { key, value, index: null }) | ||
super(seq, tree, { key, value, index: null, inflated: null }) | ||
this.pendingIndex = index | ||
@@ -392,3 +394,4 @@ } | ||
this._sessions = opts.sessions !== false | ||
this._keyCache = new KeyCache() | ||
this._keyCache = new Cache() | ||
this._nodeCache = new Cache() | ||
@@ -571,2 +574,3 @@ this._batches = [] | ||
this._nodeCache.gc(this.core.length) | ||
this._keyCache.gc(this.core.length) | ||
@@ -736,2 +740,17 @@ } | ||
async _getNode (seq) { | ||
const cached = this.tree._nodeCache.get(seq) | ||
if (cached !== null) return cached | ||
const entry = await this.core.get(seq, { ...this.options, valueEncoding: Node }) | ||
if (entry === null) throw BLOCK_NOT_AVAILABLE() | ||
const wrap = { | ||
key: entry.key, | ||
value: entry.value, | ||
index: entry.index, | ||
inflated: null | ||
} | ||
this.tree._nodeCache.set(seq, wrap) | ||
return wrap | ||
} | ||
async getBlock (seq) { | ||
@@ -742,4 +761,3 @@ if (this.rootSeq === 0) this.rootSeq = seq | ||
this.onseq(seq) | ||
const entry = await this.core.get(seq, { ...this.options, valueEncoding: Node }) | ||
if (entry === null) throw BLOCK_NOT_AVAILABLE() | ||
const entry = await this._getNode(seq) | ||
b = new BlockEntry(seq, this, entry) | ||
@@ -746,0 +764,0 @@ if (this.blocks && (this.blocks.size - this.length) < 128) this.blocks.set(seq, b) |
{ | ||
"name": "hyperbee", | ||
"version": "2.19.2", | ||
"version": "2.19.3", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
@@ -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
96139
2665