- $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')';
- $comment_ids = $wpdb->get_col( "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" );
+ if ( $uncached_parent_ids ) {
+ // 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() );
+ foreach ( $level_comments as $level_comment ) {
+ $parent_map[ $level_comment->comment_parent ][] = $level_comment->comment_ID;
+ $child_ids[] = $level_comment->comment_ID;
+ }
+
+ foreach ( $parent_map as $parent_id => $children ) {
+ $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed";
+ wp_cache_set( $cache_key, $children, 'comment' );
+ }
+ }