Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Fix double prefixes#81

Merged
vweevers merged 2 commits intomasterfrom
fix-double-prefix
Oct 8, 2019
Merged

Fix double prefixes#81
vweevers merged 2 commits intomasterfrom
fix-double-prefix

Conversation

@vweevers
Copy link
Copy Markdown
Member

@vweevers vweevers commented Oct 8, 2019

In two situations:

  • When reopening a nested sublevel, because on open we add the parent's prefix to the child's prefix. Open twice, and you get a double prefix. Fixed by keeping around the original prefix.
  • When having more than 2 nested sublevels. This resulted in subdown wrapping subdown, effectively applying a double prefix to keys. Fixed by tweaking the unwrapping voodoo.

Closes #78. This PR is an alternative to #79, which fixes more issues but is WIP, more invasive and semver-major, while this is semver-patch (with a caveat).

In two situations:

- When reopening a nested sublevel, because on open we add the
  parent's prefix to the child's prefix. Open twice, and you get a
  double prefix. Fixed by keeping around the original prefix.
- When having more than 2 nested sublevels. This resulted in
  subdown wrapping subdown, effectively applying a double prefix
  to keys. Fixed by tweaking the unwrapping voodoo.
@vweevers vweevers added the semver-patch Bug fixes that are backward compatible label Oct 8, 2019
Comment thread leveldown.js Outdated
self.prefix = subdb.prefix + self.prefix
self.leveldown = reachdown(subdb.db, matchdown, false)
self.prefix = subdb.prefix + self.ownPrefix
self.leveldown = subdb.leveldown || reachdown(subdb.db, matchdown, false)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only need 1 one of these solutions (either subdb.leveldown or reachdown(..)), not sure which I like best.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna go with subdb.leveldown because reachdown(sub.db) is like taking a detour (it goes: own levelup -> encoding-down -> subleveldown -> external levelup -> encoding-down -> leveldown).

@MeirionHughes
Copy link
Copy Markdown
Member

MeirionHughes commented Oct 8, 2019

I've approved solely on the basis you've added a unit test for the case - I'm afraid I don't know the ramifications of the choice you outlined above; the best I can suggest/ask is whether one approach is better at handling "exotic" subdowns. i.e. sub(encryptdown(sub(db, "foo")), "bar") etc...

@vweevers
Copy link
Copy Markdown
Member Author

vweevers commented Oct 8, 2019

@MeirionHughes Roger, thanks. We support those exotic situations since 4.1.3 and have a test for it :)

@vweevers vweevers merged commit 3e8c1af into master Oct 8, 2019
@vweevers vweevers deleted the fix-double-prefix branch October 8, 2019 09:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

semver-patch Bug fixes that are backward compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Applies prefix twice on nested sublevel

3 participants