Skip to content

Router key iteration / count #112

@corrideat

Description

@corrideat

Problem

The current router DB backend simply iterates over all keys in each backend, same with count. This isn't necessarily correct, because it doesn't take into account which keys would actually be used, based on the prefix configured.

  async * iterKeys () {
    for (const backend of new Set(Object.values(this.backends))) {
      yield * backend.iterKeys()
    }
  }

  async keyCount () {
    let count = 0
    for (const backend of new Set(Object.values(this.backends))) {
      count += await backend.keyCount()
    }
    return count
  }

Example:

Configuration is:

[database.backendOptions.router]
"*" = { name = "fs", options = { } }
z = { name = "redis", options = { } }

Say that redis has a key called foo. This would be reported both in iterKeys and keyCount, even though the redis backend will never be used for this key.

Solution

Improve the logic to report only relevant keys.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions