Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

versionLimit, minVersion, maxVersion are filtered in-memory #6

Open
timoxley opened this issue Aug 17, 2015 · 0 comments
Open

versionLimit, minVersion, maxVersion are filtered in-memory #6

timoxley opened this issue Aug 17, 2015 · 0 comments

Comments

@timoxley
Copy link

This should probably be implemented as levelup's gte/lte/limit options instead.

    var filter = through({objectMode: true}, function (record, encoding, cb) {
      if (typeof record != "object") {
        if (options.keys) record = {key: record}
        if (options.values) record = {value: record}
        // if both are true... wtf?
      }

      // split off version key & add it to record
      var kv = unmakeKey(sep, record.key)

      if (options.versionLimit) {
        if (kv.key != this.currentKey) {
          this.currentKey = kv.key
          this.currentCount = 0
        }
        if (this.currentCount++ >= options.versionLimit) return cb()
      }

      if (kv.version >= options.minVersion && kv.version <= options.maxVersion) {
        record.version = kv.version
        record.key = kv.key
        this.push(record)
      }
      cb()
    })

level-version/index.js

Lines 186 to 210 in 0941eb7

var filter = through({objectMode: true}, function (record, encoding, cb) {
if (typeof record != "object") {
if (options.keys) record = {key: record}
if (options.values) record = {value: record}
// if both are true... wtf?
}
// split off version key & add it to record
var kv = unmakeKey(sep, record.key)
if (options.versionLimit) {
if (kv.key != this.currentKey) {
this.currentKey = kv.key
this.currentCount = 0
}
if (this.currentCount++ >= options.versionLimit) return cb()
}
if (kv.version >= options.minVersion && kv.version <= options.maxVersion) {
record.version = kv.version
record.key = kv.key
this.push(record)
}
cb()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant