WordPress.org

Make WordPress Core

Changeset 13653


Ignore:
Timestamp:
03/10/2010 09:32:03 PM (10 years ago)
Author:
ryan
Message:

Cache get_lastpostmodified() results. see #12575

File:
1 edited

Legend:

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

    r13576 r13653  
    37193719
    37203720/**
    3721  * Retrieve the date the the last post was published.
     3721 * Retrieve the date that the last post was published.
    37223722 *
    37233723 * The server timezone is the default and is the difference between GMT and
     
    37713771 * @uses apply_filters() Calls 'get_lastpostmodified' filter
    37723772 *
    3773  * @global mixed $cache_lastpostmodified Stores the date the last post was modified
    3774  *
    37753773 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
    37763774 * @return string The date the post was last modified.
    37773775 */
    37783776function get_lastpostmodified($timezone = 'server') {
    3779     global $cache_lastpostmodified, $wpdb, $blog_id;
     3777    global $wpdb;
     3778
    37803779    $add_seconds_server = date('Z');
    3781     if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) {
    3782         switch(strtolower($timezone)) {
    3783             case 'gmt':
    3784                 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3785                 break;
    3786             case 'blog':
    3787                 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3788                 break;
    3789             case 'server':
    3790                 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3791                 break;
    3792         }
    3793         $lastpostdate = get_lastpostdate($timezone);
    3794         if ( $lastpostdate > $lastpostmodified ) {
    3795             $lastpostmodified = $lastpostdate;
    3796         }
    3797         $cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified;
    3798     } else {
    3799         $lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone];
    3800     }
     3780    $timezone = strtolower( $timezone );
     3781
     3782    $lastpostmodified = wp_cache_get( "lastpostmodified:$timezone", 'timeinfo' );
     3783    if ( $lastpostmodified )
     3784        return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
     3785   
     3786    switch ( strtolower($timezone) ) {
     3787        case 'gmt':
     3788            $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3789            break;
     3790        case 'blog':
     3791            $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3792            break;
     3793        case 'server':
     3794            $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3795            break;
     3796    }
     3797   
     3798    $lastpostdate = get_lastpostdate($timezone);
     3799    if ( $lastpostdate > $lastpostmodified )
     3800        $lastpostmodified = $lastpostdate;
     3801
     3802    if ( $lastpostmodified )
     3803        wp_cache_set( "lastpostmodified:$timezone", $lastpostmodified, 'timeinfo' );
     3804
    38013805    return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
    38023806}
     
    40154019            $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
    40164020        do_action('private_to_published', $post->ID);  // Deprecated, use private_to_publish
     4021    }
     4022
     4023    // If published posts changed clear the lastpostmodified cache
     4024    if ( 'publish' == $new_status || 'publish' == $old_status) {
     4025        wp_cache_delete( 'lastpostmodified:server', 'timeinfo' );
     4026        wp_cache_delete( 'lastpostmodified:gmt',    'timeinfo' );
     4027        wp_cache_delete( 'lastpostmodified:blog',   'timeinfo' );
    40174028    }
    40184029
Note: See TracChangeset for help on using the changeset viewer.