Make WordPress Core


Ignore:
Timestamp:
01/01/2008 05:03:52 PM (17 years ago)
Author:
ryan
Message:

Defer comment counting. Props tellyworth. fixes #5557

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r6364 r6532  
    492492}
    493493
    494 
    495 function wp_update_comment_count($post_id) {
     494function wp_defer_comment_counting($defer=NULL) {
     495    static $_defer = false;
     496   
     497    if ( is_bool($defer) ) {
     498        $_defer = $defer;
     499        // flush any deferred counts
     500        if ( !$defer )
     501            wp_update_comment_count( NULL, true );
     502    }
     503   
     504    return $_defer;
     505}
     506
     507function wp_update_comment_count($post_id, $do_deferred=false) {
     508    static $_deferred = array();
     509   
     510    if ( $do_deferred ) {
     511        $_deferred = array_unique($_deferred);
     512        foreach ( $_deferred as $i => $_post_id ) {
     513            wp_update_comment_count_now($_post_id);
     514            unset( $_deferred[$i] );
     515        }
     516    }
     517   
     518    if ( wp_defer_comment_counting() ) {
     519        $_deferred[] = $post_id;
     520        return true;
     521    }
     522    elseif ( $post_id ) {
     523        return wp_update_comment_count_now($post_id);
     524    }
     525       
     526}
     527
     528function wp_update_comment_count_now($post_id) {
    496529    global $wpdb;
    497530    $post_id = (int) $post_id;
Note: See TracChangeset for help on using the changeset viewer.