Make WordPress Core

Changeset 5666


Ignore:
Timestamp:
06/08/2007 12:20:22 AM (19 years ago)
Author:
ryan
Message:

Comment caching. Reduce queries on edit-comments.php page. Add non-persistent cache groups. Hat tip to hovenko. fixes #4387

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r5508 r5666  
    152152</thead>';
    153153                foreach ($comments as $comment) {
    154                 $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     154                $post = get_post($comment->comment_post_ID);
     155                $authordata = get_userdata($post->post_author);
    155156                $comment_status = wp_get_comment_status($comment->comment_ID);
    156157                $class = ('alternate' == $class) ? '' : 'alternate';
  • trunk/wp-admin/includes/template.php

    r5637 r5666  
    251251        }
    252252
     253        update_comment_cache($comments);
     254
    253255        $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
    254256
     
    261263        $comment =& get_comment( $id );
    262264        $class = '';
    263         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     265        $post = get_post($comment->comment_post_ID);
     266        $authordata = get_userdata($post->post_author);
    264267        $comment_status = wp_get_comment_status($comment->comment_ID);
    265268        if ( 'unapproved' == $comment_status )
  • trunk/wp-includes/cache.php

    r5544 r5666  
    6464        var $non_existant_objects = array ();
    6565        var $global_groups = array ('users', 'userlogins', 'usermeta');
     66        var $non_persistent_groups = array('comment');
    6667        var $blog_id;
    6768        var $cold_cache_hits = 0;
     
    309310                $errors = 0;
    310311                foreach ($this->dirty_objects as $group => $ids) {
     312                        if ( in_array($group, $this->non_persistent_groups) )
     313                                continue;
     314
    311315                        $group_dir = $this->make_group_dir($group, $dir_perms);
    312316
  • trunk/wp-includes/comment-template.php

    r5626 r5666  
    302302        $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
    303303        $wp_query->comment_count = count($wp_query->comments);
     304        update_comment_cache($comments);
    304305
    305306        define('COMMENTS_TEMPLATE', true);
  • trunk/wp-includes/comment.php

    r5329 r5666  
    7272// Handles comment caching.
    7373function &get_comment(&$comment, $output = OBJECT) {
    74         global $comment_cache, $wpdb;
     74        global $wpdb;
    7575
    7676        if ( empty($comment) ) {
     
    8080                        $_comment = null;
    8181        } elseif ( is_object($comment) ) {
    82                 if ( !isset($comment_cache[$comment->comment_ID]) )
    83                         $comment_cache[$comment->comment_ID] = &$comment;
    84                 $_comment = & $comment_cache[$comment->comment_ID];
     82                wp_cache_add($comment->comment_ID, $comment, 'comment');
     83                $_comment = $comment;
    8584        } else {
    8685                $comment = (int) $comment;
    8786                if ( isset($GLOBALS['comment']) && ($GLOBALS['comment']->comment_ID == $comment) ) {
    8887                        $_comment = & $GLOBALS['comment'];
    89                 } elseif ( !isset($comment_cache[$comment]) ) {
     88                } elseif ( ! $_comment = wp_cache_get($comment, 'comment') ) {
    9089                        $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
    91                         $comment_cache[$comment->comment_ID] = & $_comment;
    92                 } else {
    93                         $_comment = & $comment_cache[$comment];
    94                 }
    95         }
     90                        wp_cache_add($_comment->comment_ID, $_comment, 'comment');
     91                }
     92        }
     93
     94        $_comment = apply_filters('get_comment', $_comment);
    9695
    9796        if ( $output == OBJECT ) {
     
    286285                wp_update_comment_count($post_id);
    287286
     287        clean_comment_cache($comment_id);
     288
    288289        do_action('wp_set_comment_status', $comment_id, 'delete');
    289290        return true;
     
    294295        global $wpdb;
    295296
    296         $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
    297 
    298         if ( $result == NULL )
     297        $comment = get_comment($comment_id);
     298        if ( !$comment )
     299                return false;
     300
     301        $approved = $comment->comment_approved;
     302
     303        if ( $approved == NULL )
    299304                return 'deleted';
    300         elseif ( $result == '1' )
     305        elseif ( $approved == '1' )
    301306                return 'approved';
    302         elseif ( $result == '0' )
     307        elseif ( $approved == '0' )
    303308                return 'unapproved';
    304         elseif ( $result == 'spam' )
     309        elseif ( $approved == 'spam' )
    305310                return 'spam';
    306311        else
     
    439444                return false;
    440445
     446        clean_comment_cache($comment_id);
     447
    441448        do_action('wp_set_comment_status', $comment_id, $comment_status);
    442449        $comment = get_comment($comment_id);
    443450        wp_update_comment_count($comment->comment_post_ID);
     451
    444452        return true;
    445453}
     
    480488
    481489        $rval = $wpdb->rows_affected;
     490
     491        clean_comment_cache($comment_ID);
    482492        wp_update_comment_count($comment_post_ID);
    483493        do_action('edit_comment', $comment_ID);
     
    794804}
    795805
     806//
     807// Cache
     808//
     809
     810function clean_comment_cache($id) {
     811        wp_cache_delete($id, 'comment');
     812}
     813
     814function update_comment_cache($comments) {
     815        foreach ( $comments as $comment )
     816                wp_cache_add($comment->comment_ID, $comment, 'comment');
     817}
     818
    796819?>
Note: See TracChangeset for help on using the changeset viewer.