Don't apply sorting to collection until after scoping #7205
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider sorting that requires a
JOIN
as part of the SQL query (or really anything that was raised in #3085):Oftentimes, including that
JOIN
is not a huge deal in terms of performance, however, there have been situations where that table/column can increase the time it takes for a query to run by a couple hundred milliseconds, for various reasons.Increasing the time to load the page slightly (0.1s) is not a big deal, in an admin, but imagine if you had 7-10 different scopes on that page as well? Because scopes leverage
collection_before_scope
, they will proceed to include theJOIN
in their query, even though it is only necessary to do sorting of a collection that is not actually being sorted, only counted.Applying sorting of the collection after scoping, instead of before, should have no bearing on the end-result, while ensuring that any custom sorting logic is not needlessly applied to all scope count queries.