Changeset 37625 for trunk/src/wp-includes/class-wp-comment-query.php
- Timestamp:
- 06/02/2016 06:27:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r37539 r37625 743 743 } 744 744 745 if ( $this->query_vars['hierarchical'] && ! $this->query_vars['parent'] ) { 746 $this->query_vars['parent'] = 0; 747 } 748 749 if ( '' !== $this->query_vars['parent'] ) { 750 $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $this->query_vars['parent'] ); 745 $parent = $this->query_vars['parent']; 746 if ( $this->query_vars['hierarchical'] && ! $parent ) { 747 $parent = 0; 748 } 749 750 if ( '' !== $parent ) { 751 $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent ); 751 752 } 752 753 … … 942 943 } 943 944 945 $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); 946 $last_changed = wp_cache_get( 'last_changed', 'comment' ); 947 if ( ! $last_changed ) { 948 $last_changed = microtime(); 949 wp_cache_set( 'last_changed', $last_changed, 'comment' ); 950 } 951 944 952 // Fetch an entire level of the descendant tree at a time. 945 953 $level = 0; 946 954 do { 947 $parent_ids = $levels[ $level ]; 948 if ( ! $parent_ids ) { 949 break; 950 } 951 952 $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')'; 953 $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" ); 955 // Parent-child relationships may be cached. Only query for those that are not. 956 $child_ids = $uncached_parent_ids = array(); 957 $_parent_ids = $levels[ $level ]; 958 foreach ( $_parent_ids as $parent_id ) { 959 $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed"; 960 $parent_child_ids = wp_cache_get( $cache_key, 'comment' ); 961 if ( false !== $parent_child_ids ) { 962 $child_ids = array_merge( $child_ids, $parent_child_ids ); 963 } else { 964 $uncached_parent_ids[] = $parent_id; 965 } 966 } 967 968 if ( $uncached_parent_ids ) { 969 $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $uncached_parent_ids ) ) . ')'; 970 $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" ); 971 972 // Cache parent-child relationships. 973 $parent_map = array_fill_keys( $uncached_parent_ids, array() ); 974 foreach ( $level_comments as $level_comment ) { 975 $parent_map[ $level_comment->comment_parent ][] = $level_comment->comment_ID; 976 $child_ids[] = $level_comment->comment_ID; 977 } 978 979 foreach ( $parent_map as $parent_id => $children ) { 980 $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed"; 981 wp_cache_set( $cache_key, $children, 'comment' ); 982 } 983 } 954 984 955 985 $level++; 956 $levels[ $level ] = $c omment_ids;957 } while ( $c omment_ids );986 $levels[ $level ] = $child_ids; 987 } while ( $child_ids ); 958 988 959 989 // Prime comment caches for non-top-level comments.
Note: See TracChangeset
for help on using the changeset viewer.