mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Comments: Improve WP_Comment_Query count query performance by setting 'order by' to 'none'.
In cases where `WP_Comment_Query` or `get_comments` is employed with the 'count' parameter set to true, specify 'order by' as 'none'. Since these queries serve solely to determine the count of comments matching specific query parameters, the 'order by' clause becomes redundant and places unnecessary strain on the database server, resulting in slower query execution. Given that count queries are executed on every admin request to retrieve comment counts, this change enhances the performance of the wp-admin interface. Props guss77, davidbaumwald, SergeyBiryukov, westonruter, peterwilsoncc, foliovision, hareesh-pillai, spacedmonkey. Fixes #58368 git-svn-id: https://develop.svn.wordpress.org/trunk@56747 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -396,6 +396,7 @@ function get_comment_count( $post_id = 0 ) {
|
||||
$args = array(
|
||||
'count' => true,
|
||||
'update_comment_meta_cache' => false,
|
||||
'orderby' => 'none',
|
||||
);
|
||||
if ( $post_id > 0 ) {
|
||||
$args['post_id'] = $post_id;
|
||||
@@ -1114,6 +1115,7 @@ function get_page_of_comment( $comment_id, $args = array() ) {
|
||||
'fields' => 'ids',
|
||||
'count' => true,
|
||||
'status' => 'approve',
|
||||
'orderby' => 'none',
|
||||
'parent' => 0,
|
||||
'date_query' => array(
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user