Opened 10 years ago
Closed 10 years ago
#29902 closed enhancement (fixed)
Allow no ORDER BY for comments in WP_Comment_Query
Reported by: | psycleuk | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 4.0 |
Component: | Comments | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
The order by filters within WP_Query allow completely removing any order by appearing within the resultant posts database query, the same is true for the comments feed query in WP_Query. However it isn't the case for WP_Comment_Query.
Within WP_Comment_Query the $groupby variable is checked and has the prefix 'GROUP BY ' added. What I propose is the same for $orderby.
This would mean consistency between the two Query classes, and for those plugins that use the comments table for custom comment types, it'd allow removing any order by if the plugin deemed it unnecessary. For example with the latter requesting comments with a post_id, comment_type and user_id triggers a MySQL filesort even if the result is a single entry. Having no ORDER BY would skip the filesort yet have the same result.
My attached patch simply duplicates what the existing $groupby does.
Attachments (1)
Change History (5)
#3
@
10 years ago
- Milestone changed from Awaiting Review to 4.1
psycleuk - Thanks very much for the ticket and the patch.
We can't go with exactly your suggestion - the logic https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/comment.php#L318 currently makes it so that $orderby
can never be empty, so your if ( $orderby )
condition will always be hit. We'll do what WP_Query
does: skip the ORDER BY with boolean false or the word 'none'.
+1, Looks good to me :)