* @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.
// $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' );
}
$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;
}
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() );
// 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 ] );
}