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

Adding a sort option to a query includes deleted documents in the indexeddb adapter #8438

Closed
nirvdrum opened this issue Jan 18, 2022 · 7 comments · Fixed by #8531
Closed
Labels
bug Confirmed bug pinned for issues that should stay open stale

Comments

@nirvdrum
Copy link

nirvdrum commented Jan 18, 2022

Issue

When sending a query to PouchDB using this adapter, deleted documents show up in the results if any sort option is added to the query. E.g, using the following query:

{
  "selector": {
    "rank": {
      "$gt": ""
    }
  },
  "sort": [
    {
      "rank": "asc"
    }
  ]
}

If I remove the sort property, deleted documents will not be included in the results. With the sort present, deleted documents appear. This is a change in behavior from pouchdb-adapter-idb. For the time being, I need to add my own selector to exclude deleted documents any time I want to sort values.

Info

  • Environment: Browser
  • Platform: Firefox
  • Adapter: indexeddb
  • Server: None
  • Version: 7.2.2
@nirvdrum nirvdrum changed the title Adding a sort option to a query includes deleted documents Adding a sort option to a query includes deleted documents in the indexeddb adapter Jan 18, 2022
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@nirvdrum
Copy link
Author

I'm sorry. I can't keep up with all the stalebot notifications. For anyone coming across this issue, it's still present despite the issue being closed (I can't re-open it).

@AlbaHerrerias AlbaHerrerias reopened this Apr 18, 2022
@AlbaHerrerias AlbaHerrerias added bug Confirmed bug pinned for issues that should stay open and removed stale labels Apr 18, 2022
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale label Jun 18, 2022
@nirvdrum
Copy link
Author

Not fixed yet, I don't think.

@nirvdrum
Copy link
Author

Is the bot broken? I commented on the issue and it closed the issue anyway.

@Terreii
Copy link
Contributor

Terreii commented Jul 14, 2022

I could recreate the bug! I just don't have a solution, yet.

@Terreii
Copy link
Contributor

Terreii commented Jul 14, 2022

Found it!
The new indexeddb adapter uses the native IndexedDB indexes. Problem with them is, that they go over all entries.
Therefore PouchDB adds a field to the beginning of all indexes where deleted = 1 and not deleted = 0.
If you use sort, it can happen that PouchDB will use IDBKeyRange.lowerBound(). Which will include deleted docs (because they are indexed later).
So I replaced the IDBKeyRange.lowerBound() with a IDBKeyRange.bound().

AlbaHerrerias pushed a commit to neighbourhoodie/pouchdb that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug pinned for issues that should stay open stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants