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

Create compound index with primary key and sort by its items #2456

Merged
merged 4 commits into from Aug 25, 2020

Conversation

dome4
Copy link
Contributor

@dome4 dome4 commented Aug 22, 2020

This PR contains:

A bugfix concerning compound indexes

Describe the problem you have without this PR

I tried to create a compound index (age + id) that contains the primary key (id) of the schema and sort docs by the attributes of the compound index (see test). This fails with the error message "cannot sort on field(s) 'age' when using the default index". Why is the default index ('_id)' used here, although an appropriate custom index has been defined?

The first problem was that in RxStoragePouchDbClass - prepareQuery() the primary key is changed to '_id' and therefore the new custom index does not match the attribute anymore:

const useKey = key === primPath ? '_id' : key;

Therefore in my opinion the method createIndex() of RxCollection has to be adapted and the change of the primary key has to be done as well.

Second, the order of the attributes in sort() is changed. This has proven to be a problem with the util sortObject(). When the method is called recursively, the param noArraySort is currently not passed to further calls, which results in nested arrays being sorted. The problem occurred in the method toString() of RxQuery, so the custom index was not found. Additionally, the test typeof obj === 'object' in the method is not sufficient to exclude an array. Therefore I have added !Array.isArray(obj) here.

Hopefully I explained the problem sufficiently :)

Todos

  • Changelog

@dome4 dome4 changed the title Create compound index with primary key and sort by it Create compound index with primary key and sort by its items Aug 22, 2020
@pubkey pubkey merged commit a1e83e0 into pubkey:master Aug 25, 2020
@pubkey
Copy link
Owner

pubkey commented Aug 25, 2020

@dome4 great work, merged.

pubkey added a commit that referenced this pull request Aug 25, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants