-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(db-mongodb): Do not add fallback sort if user sent a sort order #12888
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
base: main
Are you sure you want to change the base?
Conversation
the current code pushes createdAt sort even if user sent a sort order , which makes it dual sort and causes performance issue, if user sent a sort do not add any other sort, fixes this payloadcms#12690
Pull Request titles must follow the Conventional Commits specification and have valid scopes. The subject "Do not add fallback sort if user sent a sort order" found in the pull request title "fix(db-mongodb): Do not add fallback sort if user sent a sort order"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other idea I can offer would be to add an additional db configuration arg to include disableFallbackSort or some other better name.
That way, for your implementation you'd have the choice because I can see why this would not be ideal.
One other idea that comes to mind, you could add all your field indexes as compound indexes with the createdAt: -1
so that sorting on the your collection is as performent as possible by the DB. That might actually be the best scenario and something we could look into.
What do you think?
hi,
Secondly some data/queries do not care about createdAt, current implementation just throw away the advantage of covered queries in MongodB https://www.mongodb.com/docs/manual/core/query-optimization/#covered-query looking at the comment in PR which implemented this, seems to assume that user only creates index in payload which is wrong assumption. whatever you guys choose to do, adding another sort when user sent an explicit sort is not right , if at all this is required it should be behind a flag not by default, current implementation makes all queries slow |
What do you think @r1tsuu and @paulpopus? |
If you order by a unique field (or compound unique fields), it should at least not add any fallback. |
We don't have the field config at the this point in callstack without finding it in the collection config. |
the current code pushes -createdAt sort even if user sent a sort order , which makes it dual sort and causes performance issue, only visible in large database, if user sent a sort do not add any other sort, fixes this #12690