Make WordPress Core

Ticket #21115: 21115.diff

File 21115.diff, 2.3 KB (added by nacin, 12 years ago)
  • wp-includes/comment.php

     
    406406 */
    407407function get_lastcommentmodified($timezone = 'server') {
    408408        global $wpdb;
    409         static $cache_lastcommentmodified = array();
    410409
    411         if ( isset($cache_lastcommentmodified[$timezone]) )
    412                 return $cache_lastcommentmodified[$timezone];
     410        $timezone = strtolower( $timezone );
     411        if ( ! in_array( $timezone, array( 'gmt', 'blog', 'server' ) ) )
     412                return;
    413413
     414        if ( $last_modified = wp_cache_get( "lastmodified:$timezone", 'comment' ) )
     415                return $last_modified;
     416
    414417        $add_seconds_server = date('Z');
    415418
    416         switch ( strtolower($timezone)) {
     419        switch ( $timezone ) {
    417420                case 'gmt':
    418                         $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
     421                        $last_modified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
    419422                        break;
    420423                case 'blog':
    421                         $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
     424                        $last_modified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
    422425                        break;
    423426                case 'server':
    424                         $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server));
     427                        $last_modified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server));
    425428                        break;
    426429        }
    427430
    428         $cache_lastcommentmodified[$timezone] = $lastcommentmodified;
    429 
    430         return $lastcommentmodified;
     431        wp_cache_add( "lastmodified:$timezone", $last_modified, 'comment' );
     432        return $last_modified;
    431433}
    432434
    433435/**
     
    19301932                wp_cache_delete($id, 'comment');
    19311933
    19321934        wp_cache_set('last_changed', time(), 'comment');
     1935        wp_cache_delete( 'lastmodified:gmt', 'comment' );
     1936        wp_cache_delete( 'lastmodified:server', 'comment' );
     1937        wp_cache_delete( 'lastmodified:blog', 'comment' );
    19331938}
    19341939
    19351940/**