-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
ORDER BY
clause from COUNT
queries
Since we just used the pre-assembled relations to then call `#size` on them, this caused queries like this to be sent to the database: ``` SELECT COUNT(*) FROM ( SELECT 1 AS one FROM `posts` ORDER BY `posts`.`author` DESC, `posts`.`id` DESC LIMIT 3 ) subquery_for_count ``` The `ORDER BY` part will never influence the number of returned records. But depending on the used database and their query optimization settings, it will make the query less performant. Therefore, remove any order from the queries before calling `#size` on them. With `ActiveRecord` this can be achieved by calling `#reorder` on the relation with an empty string.
- Loading branch information
1 parent
4009f7e
commit dfc7e96
Showing
2 changed files
with
7 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters