Fix 'timeinfo' cache invalidation. Fixes #14922

git-svn-id: https://develop.svn.wordpress.org/trunk@16537 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
scribu 2010-11-22 21:45:45 +00:00
parent ef9b5fb1ec
commit 40c993af3f
2 changed files with 9 additions and 11 deletions

View File

@ -4171,23 +4171,20 @@ function _get_last_post_time( $timezone, $field ) {
if ( !in_array( $field, array( 'date', 'modified' ) ) ) if ( !in_array( $field, array( 'date', 'modified' ) ) )
return false; return false;
$post_types = get_query_var('post_type'); $timezone = strtolower( $timezone );
if ( empty($post_types) )
$post_types = 'post';
$post_types = apply_filters( "get_lastpost{$field}_post_types", (array) $post_types ); $key = "lastpost{$field}:$timezone";
$key = "lastpost{$field}:" . get_current_blog_id() . ":$timezone:" . md5( serialize( $post_types ) );
$date = wp_cache_get( $key, 'timeinfo' ); $date = wp_cache_get( $key, 'timeinfo' );
if ( !$date ) { if ( !$date ) {
$add_seconds_server = date('Z'); $add_seconds_server = date('Z');
$post_types = get_post_types( array( 'publicly_queryable' => true ) );
array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
$post_types = "'" . implode( "', '", $post_types ) . "'"; $post_types = "'" . implode( "', '", $post_types ) . "'";
switch ( strtolower( $timezone ) ) { switch ( $timezone ) {
case 'gmt': case 'gmt':
$date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
break; break;
@ -4450,9 +4447,10 @@ function _transition_post_status($new_status, $old_status, $post) {
// If published posts changed clear the lastpostmodified cache // If published posts changed clear the lastpostmodified cache
if ( 'publish' == $new_status || 'publish' == $old_status) { if ( 'publish' == $new_status || 'publish' == $old_status) {
wp_cache_delete( 'lastpostmodified:server', 'timeinfo' ); foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
wp_cache_delete( 'lastpostmodified:gmt', 'timeinfo' ); wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
wp_cache_delete( 'lastpostmodified:blog', 'timeinfo' ); wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' );
}
} }
// Always clears the hook in case the post status bounced from future to draft. // Always clears the hook in case the post status bounced from future to draft.

View File

@ -35,7 +35,7 @@ if ( function_exists( 'date_default_timezone_set' ) )
wp_unregister_GLOBALS(); wp_unregister_GLOBALS();
// Ensure these global variables do not exist so they do not interfere with WordPress. // Ensure these global variables do not exist so they do not interfere with WordPress.
unset( $wp_filter, $cache_lastcommentmodified, $cache_lastpostdate ); unset( $wp_filter, $cache_lastcommentmodified );
// Standardize $_SERVER variables across setups. // Standardize $_SERVER variables across setups.
wp_fix_server_vars(); wp_fix_server_vars();