Defer comment counting. Props tellyworth. fixes #5557

git-svn-id: https://develop.svn.wordpress.org/trunk@6532 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-01-01 17:03:52 +00:00
parent cdbb434e6a
commit d633240113
2 changed files with 71 additions and 25 deletions
+34 -1
View File
@@ -491,8 +491,41 @@ function wp_update_comment($commentarr) {
return $rval;
}
function wp_defer_comment_counting($defer=NULL) {
static $_defer = false;
if ( is_bool($defer) ) {
$_defer = $defer;
// flush any deferred counts
if ( !$defer )
wp_update_comment_count( NULL, true );
}
return $_defer;
}
function wp_update_comment_count($post_id) {
function wp_update_comment_count($post_id, $do_deferred=false) {
static $_deferred = array();
if ( $do_deferred ) {
$_deferred = array_unique($_deferred);
foreach ( $_deferred as $i => $_post_id ) {
wp_update_comment_count_now($_post_id);
unset( $_deferred[$i] );
}
}
if ( wp_defer_comment_counting() ) {
$_deferred[] = $post_id;
return true;
}
elseif ( $post_id ) {
return wp_update_comment_count_now($post_id);
}
}
function wp_update_comment_count_now($post_id) {
global $wpdb;
$post_id = (int) $post_id;
if ( !$post_id )