-
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.
Change queries used for pagination when
order_by
parameter is passed
The previous logic relied on using concatenation to generate a unique field that could both be filtered and sorted over. This was done with the assumption that databases would allow adding an index on such a concatenated field. But this is actually not the case, neither MySQL nor Postgres support indices on functions like `CONCAT`. Therefore, the queries used by the gem had a vert poor performance. To combat this, the queries are now changed to query the given `order_by` field and the ID field separately and also have them separately in the `ORDER BY` clause. This allows making use of a compound or multicolumn index on the combination of the two fields. Since both MySQL and Postgres support efficient use of compound indices when accessing / filtering over / ordering by either all fields of the index or the leftmost fields only, and index on `(<custom_column>, id)` will ensure a high performance of these queries. Furthermore, abandoning the concatenation now also ensures that non-string columns are ordered as expected. Before, e.g. integer columns were treated as text columns, leading to weird orders like `1, 10, 11, 2, 3, 4`. This has also been solved with these changes. However, due to this changing the order of the returned results, releasing this cause a breaking change. Since the set of tables this gem can be used on will surely be fairly limited, we want the string returned by the `Paginator#id_column` method to be frozen. In Ruby < 3.0 this is automatic through the magic comment on top of the file, however in Ruby 3.0 this is no longer the case for interpolated strings. Therefore it has to be manually frozen and the Rubocop rule (which checks for Ruby 2.5 syntax) has to be adjusted accordingly.
- Loading branch information
1 parent
bcbb3f1
commit 4009f7e
Showing
6 changed files
with
105 additions
and
65 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
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
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