fix(storage): deepen hyperbee secondary-index and hyperdrive snapshots
- Fix missing totalPrimaries() on bee-secondary-index (runtime bug in getStats) - Add indexPutMany, lookupFirst, and tests for secondary index - drive-version-snapshot: findByLabel, latestSnapshot, deleteSnapshot, merge gossip Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -58,10 +58,39 @@ class HyperP2PDriveVersionSnapshot extends EventEmitter {
|
||||
return this._snapshots.get(id) || null
|
||||
}
|
||||
|
||||
findByLabel (label) {
|
||||
assertNonEmpty(label, 'label')
|
||||
return this.listSnapshots().filter((s) => s.label === label)
|
||||
}
|
||||
|
||||
latestSnapshot (label = null) {
|
||||
const list = label ? this.findByLabel(label) : this.listSnapshots()
|
||||
return list.length ? list[0] : null
|
||||
}
|
||||
|
||||
deleteSnapshot (id) {
|
||||
const ok = this._snapshots.delete(id)
|
||||
if (ok) {
|
||||
sendGossip(this, { type: 'snapshot-delete', id })
|
||||
this._stats.gossipOut++
|
||||
this.emit('delete', { id })
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
snapshotCount () {
|
||||
return this._snapshots.size
|
||||
}
|
||||
|
||||
_onGossip (d) {
|
||||
if (d?.type === 'snapshot-delete') {
|
||||
this._snapshots.delete(d.id)
|
||||
return
|
||||
}
|
||||
if (!d || d.type !== 'snapshot' || !d.snap) return
|
||||
this._stats.gossipIn++
|
||||
this._snapshots.set(d.snap.id, d.snap)
|
||||
const prev = this._snapshots.get(d.snap.id)
|
||||
if (!prev || d.snap.at >= prev.at) this._snapshots.set(d.snap.id, d.snap)
|
||||
}
|
||||
|
||||
getStats () {
|
||||
|
||||
Reference in New Issue
Block a user