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

fix: allow empty prefix option #184

Merged
merged 2 commits into from
Nov 29, 2019
Merged

Conversation

achingbrain
Copy link
Contributor

This PR changes the default behaviour of the constructor to allow empty prefixes in databases - previously if you passed '' as the prefix it would set it to level-js-.

index.js Outdated Show resolved Hide resolved
@vweevers vweevers added this to Review in Level (old board) Nov 25, 2019
@vweevers
Copy link
Member

Could this be considering a breaking change?

Co-Authored-By: Vincent Weevers <mail@vincentweevers.nl>
@achingbrain
Copy link
Contributor Author

Could this be considering a breaking change?

I think this fixes a bug - the docs say:

The database name will be prefixed with options.prefix

which was not the case if you used '' as the prefix so I'm not sure that it's a breaking change.

@vweevers
Copy link
Member

It breaks the expectation one might have that an empty prefix is treated as no prefix.

@achingbrain
Copy link
Contributor Author

True, but thats not the expectation I had 🤣

@achingbrain
Copy link
Contributor Author

Wait, hang on - what do you mean by 'empty' here? My expectation was that passing an empty string '' as the prefix would cause the database name to be prefixed with '', but it was being prefixed with level-js- and it seems with the current implementation there's no way to not have a prefix.

If I passed undefined (or null, to a lesser degree) I would expect the default to be set.

@vweevers
Copy link
Member

and it seems with the current implementation there's no way to not have a prefix

That's true. Your use case (of not having a prefix) didn't come up before.

@vweevers
Copy link
Member

In that sense it's a new feature so I'm making this semver-minor, be on the safe side.

@vweevers vweevers added the semver-minor New features that are backward compatible label Nov 29, 2019
@vweevers
Copy link
Member

I'm splitting hairs now, but after reading ipfs/js-ipfs-repo#215 I see that level-js did support an empty prefix before (courtesy of IDBWrapper). So, semver-patch.

@achingbrain ipfs is currently on level-js@4 (pending ipfs/js-datastore-level#23) so would you like for this PR to be backported to 4x?

@vweevers vweevers added semver-patch Bug fixes that are backward compatible and removed semver-minor New features that are backward compatible labels Nov 29, 2019
@vweevers vweevers merged commit 521d94a into Level:master Nov 29, 2019
Level (old board) automation moved this from Review to Done Nov 29, 2019
@vweevers
Copy link
Member

5.0.1

@achingbrain achingbrain deleted the allow-empty-prefix branch November 29, 2019 11:18
@achingbrain
Copy link
Contributor Author

would you like for this PR to be backported to 4x?

No, I think we should upgrade to the latest version of level*.

@vweevers
Copy link
Member

@achingbrain Doesn't that defeat the point of these backward compat fixes, seeing as level-js@5 can't read old databases (unless they used binary keys)?

@achingbrain
Copy link
Contributor Author

Fair point, maybe a backport would be nice 😄

@vweevers
Copy link
Member

Alternatively you can use the db.upgrade() utility. LMK what you prefer.

@achingbrain
Copy link
Contributor Author

I think we only use string keys and buffer values so that should be ok, right? UPGRADING.md says binary keys only and other types will be stringified?

Also is there any performance degradation to running db.upgrade on an already upgraded database?

@vweevers
Copy link
Member

No, string keys of old databases will sort incorrectly. IndexedDB sorts by type in addition to "content" (by which I mean the raw bytes), so the key 'foo' is distinct from the key Buffer.from('foo').

To get around that - and be compatible with how leveldown behaves - level-js@5 converts string keys to binary keys before passing them to IndexedDB, so that string and binary keys are treated as the same. I.e. it effectively no longer sorts by type.

Also is there any performance degradation to running db.upgrade on an already upgraded database?

Yes, because it doesn't check whether the database is already upgraded. Every time you call db.upgrade() it visits all keys.

@achingbrain
Copy link
Contributor Author

Ok, in that case, yes please on the backport!

We'll handle the key migrations in the https://github.com/ipfs/js-ipfs-repo-migrations when it's ready.

@vweevers
Copy link
Member

Working on the backport - but browser tests are failing in 4xx for an unrelated reason. Will update.

vweevers added a commit that referenced this pull request Nov 29, 2019
This restores a previous behavior (of `level-js` < 3) that unknown to
us, was provided by the since-removed IDBWrapper.

Backport of #184.
vweevers added a commit that referenced this pull request Nov 29, 2019
This restores a previous behavior (of `level-js` < 3) that unknown to
us, was provided by the since-removed IDBWrapper.

Backport of #184.
@vweevers
Copy link
Member

Backport landed in 4.0.2 (npm i level-js@latest-4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch Bug fixes that are backward compatible
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants