Ticket #15400: 15400-2-reduce-queries-to-number-of-posts-when-pagination-enable.patch
| File 15400-2-reduce-queries-to-number-of-posts-when-pagination-enable.patch, 1.7 KB (added by , 15 years ago) |
|---|
-
wp-includes/comment.php
792 792 'trackback' => 'trackback', 793 793 ); 794 794 795 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';796 795 797 // Count comments older than this one798 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );796 if ( ($comsdatebypost = wp_cache_get( $comment->comment_post_ID, 'page_of_comment' )) == false ) { 797 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 799 798 799 // Count comments older than this one 800 $comslist = $wpdb->get_results( $wpdb->prepare( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1'" . $comtypewhere, $comment->comment_post_ID ) ); 801 802 $comsdatebypost = array(); 803 foreach ($comslist as $pagecom) { 804 $comsdatebypost[] = strtotime( $pagecom->comment_date_gmt ); 805 } 806 wp_cache_add( $comment->comment_post_ID, $comsdatebypost, 'page_of_comment' ); 807 } 808 809 $oldercoms = 0; 810 811 foreach($comsdatebypost as $comdate) { 812 if( $comdate < strtotime($comment->comment_date_gmt) ) { 813 $oldercoms++; 814 } 815 } 816 800 817 // No older comments? Then it's page #1. 801 818 if ( 0 == $oldercoms ) 802 819 return 1;