Skip to content

Commit

Permalink
Optimize db.clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Oct 1, 2021
1 parent 90bde9d commit 47e0137
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 198 deletions.
17 changes: 16 additions & 1 deletion leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const ENCODERS = [
messages.Put,
messages.Delete,
messages.Batch,
messages.Iterator
messages.Iterator,
messages.Clear
]

const DECODERS = [
Expand Down Expand Up @@ -217,6 +218,20 @@ Multilevel.prototype._batch = function (batch, opts, cb) {
this._write(req)
}

Multilevel.prototype._clear = function (opts, cb) {
if (this._db) return this._db._clear(opts, cb)

const req = {
tag: 5,
id: 0,
options: opts,
callback: cb || noop
}

req.id = this._requests.add(req)
this._write(req)
}

Multilevel.prototype._write = function (req) {
if (this._requests.length + this._iterators.length === 1) ref(this._ref)
const enc = ENCODERS[req.tag]
Expand Down
Loading

0 comments on commit 47e0137

Please sign in to comment.