]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-comment-query.php
WordPress 4.7
[autoinstalls/wordpress.git] / wp-includes / class-wp-comment-query.php
index 0920ca229f5ae496a073de538042039a33d02820..ef8b6d545ba55751203f873011036dfb5757b0dc 100644 (file)
@@ -182,7 +182,7 @@ class WP_Comment_Query {
         *     @type array        $meta_query                Meta query clauses to limit retrieved comments by.
         *                                                   See WP_Meta_Query. Default empty.
         *     @type int          $number                    Maximum number of comments to retrieve.
-        *                                                   Default null (no limit).
+        *                                                   Default empty (no limit).
         *     @type int          $offset                    Number of comments to offset the query. Used to build
         *                                                   LIMIT clause. Default 0.
         *     @type bool         $no_found_rows             Whether to disable the `SQL_CALC_FOUND_ROWS` query.
@@ -393,11 +393,8 @@ class WP_Comment_Query {
 
                // $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
                $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
-               $last_changed = wp_cache_get( 'last_changed', 'comment' );
-               if ( ! $last_changed ) {
-                       $last_changed = microtime();
-                       wp_cache_set( 'last_changed', $last_changed, 'comment' );
-               }
+               $last_changed = wp_cache_get_last_changed( 'comment' );
+
 
                $cache_key   = "get_comments:$key:$last_changed";
                $cache_value = wp_cache_get( $cache_key, 'comment' );
@@ -972,11 +969,7 @@ class WP_Comment_Query {
                }
 
                $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
-               $last_changed = wp_cache_get( 'last_changed', 'comment' );
-               if ( ! $last_changed ) {
-                       $last_changed = microtime();
-                       wp_cache_set( 'last_changed', $last_changed, 'comment' );
-               }
+               $last_changed = wp_cache_get_last_changed( 'comment' );
 
                // Fetch an entire level of the descendant tree at a time.
                $level = 0;
@@ -995,8 +988,18 @@ class WP_Comment_Query {
                        }
 
                        if ( $uncached_parent_ids ) {
-                               $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $uncached_parent_ids ) ) . ')';
-                               $level_comments = $wpdb->get_results( "SELECT $wpdb->comments.comment_ID, $wpdb->comments.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" );
+                               // Fetch this level of comments.
+                               $parent_query_args = $this->query_vars;
+                               foreach ( $exclude_keys as $exclude_key ) {
+                                       $parent_query_args[ $exclude_key ] = '';
+                               }
+                               $parent_query_args['parent__in']    = $uncached_parent_ids;
+                               $parent_query_args['no_found_rows'] = true;
+                               $parent_query_args['hierarchical']  = false;
+                               $parent_query_args['offset']        = 0;
+                               $parent_query_args['number']        = 0;
+
+                               $level_comments = get_comments( $parent_query_args );
 
                                // Cache parent-child relationships.
                                $parent_map = array_fill_keys( $uncached_parent_ids, array() );
@@ -1017,7 +1020,7 @@ class WP_Comment_Query {
 
                // Prime comment caches for non-top-level comments.
                $descendant_ids = array();
-               for ( $i = 1; $i < count( $levels ); $i++ ) {
+               for ( $i = 1, $c = count( $levels ); $i < $c; $i++ ) {
                        $descendant_ids = array_merge( $descendant_ids, $levels[ $i ] );
                }