In wp_get_archives(), cache queries to individual cache buckets instead of storing them in one cached array. Use incrementor style passive cache invalidation.
fixes #23206 see #23173 git-svn-id: http://core.svn.wordpress.org/trunk@23385 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0f80568a7e
commit
0d54972fec
|
@ -912,103 +912,97 @@ function wp_get_archives($args = '') {
|
|||
$archive_week_end_date_format = get_option('date_format');
|
||||
}
|
||||
|
||||
//filters
|
||||
$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
|
||||
$join = apply_filters( 'getarchives_join', '', $r );
|
||||
|
||||
$output = '';
|
||||
|
||||
$last_changed = wp_cache_get( 'last_changed', 'posts' );
|
||||
if ( ! $last_changed ) {
|
||||
$last_changed = 1;
|
||||
wp_cache_set( 'last_changed', $last_changed, 'posts' );
|
||||
}
|
||||
|
||||
if ( 'monthly' == $type ) {
|
||||
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
|
||||
$key = md5($query);
|
||||
$cache = wp_cache_get( 'wp_get_archives' , 'general');
|
||||
if ( !isset( $cache[ $key ] ) ) {
|
||||
$arcresults = $wpdb->get_results($query);
|
||||
$cache[ $key ] = $arcresults;
|
||||
wp_cache_set( 'wp_get_archives', $cache, 'general' );
|
||||
} else {
|
||||
$arcresults = $cache[ $key ];
|
||||
$key = md5( $query );
|
||||
$key = "wp_get_archives:$key:$last_changed";
|
||||
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
||||
$results = $wpdb->get_results( $query );
|
||||
wp_cache_set( $key, $results, 'posts' );
|
||||
}
|
||||
if ( $arcresults ) {
|
||||
if ( $results ) {
|
||||
$afterafter = $after;
|
||||
foreach ( (array) $arcresults as $arcresult ) {
|
||||
$url = get_month_link( $arcresult->year, $arcresult->month );
|
||||
foreach ( (array) $results as $result ) {
|
||||
$url = get_month_link( $result->year, $result->month );
|
||||
/* translators: 1: month name, 2: 4-digit year */
|
||||
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
|
||||
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
|
||||
if ( $show_post_count )
|
||||
$after = ' ('.$arcresult->posts.')' . $afterafter;
|
||||
$after = ' ('.$result->posts.')' . $afterafter;
|
||||
$output .= get_archives_link($url, $text, $format, $before, $after);
|
||||
}
|
||||
}
|
||||
} elseif ('yearly' == $type) {
|
||||
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
|
||||
$key = md5($query);
|
||||
$cache = wp_cache_get( 'wp_get_archives' , 'general');
|
||||
if ( !isset( $cache[ $key ] ) ) {
|
||||
$arcresults = $wpdb->get_results($query);
|
||||
$cache[ $key ] = $arcresults;
|
||||
wp_cache_set( 'wp_get_archives', $cache, 'general' );
|
||||
} else {
|
||||
$arcresults = $cache[ $key ];
|
||||
$key = md5( $query );
|
||||
$key = "wp_get_archives:$key:$last_changed";
|
||||
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
||||
$results = $wpdb->get_results( $query );
|
||||
wp_cache_set( $key, $results, 'posts' );
|
||||
}
|
||||
if ($arcresults) {
|
||||
if ( $results ) {
|
||||
$afterafter = $after;
|
||||
foreach ( (array) $arcresults as $arcresult) {
|
||||
$url = get_year_link($arcresult->year);
|
||||
$text = sprintf('%d', $arcresult->year);
|
||||
foreach ( (array) $results as $result) {
|
||||
$url = get_year_link($result->year);
|
||||
$text = sprintf('%d', $result->year);
|
||||
if ($show_post_count)
|
||||
$after = ' ('.$arcresult->posts.')' . $afterafter;
|
||||
$after = ' ('.$result->posts.')' . $afterafter;
|
||||
$output .= get_archives_link($url, $text, $format, $before, $after);
|
||||
}
|
||||
}
|
||||
} elseif ( 'daily' == $type ) {
|
||||
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
|
||||
$key = md5($query);
|
||||
$cache = wp_cache_get( 'wp_get_archives' , 'general');
|
||||
if ( !isset( $cache[ $key ] ) ) {
|
||||
$arcresults = $wpdb->get_results($query);
|
||||
$cache[ $key ] = $arcresults;
|
||||
wp_cache_set( 'wp_get_archives', $cache, 'general' );
|
||||
} else {
|
||||
$arcresults = $cache[ $key ];
|
||||
$key = md5( $query );
|
||||
$key = "wp_get_archives:$key:$last_changed";
|
||||
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
||||
$results = $wpdb->get_results( $query );
|
||||
$cache[ $key ] = $results;
|
||||
wp_cache_set( $key, $results, 'posts' );
|
||||
}
|
||||
if ( $arcresults ) {
|
||||
if ( $results ) {
|
||||
$afterafter = $after;
|
||||
foreach ( (array) $arcresults as $arcresult ) {
|
||||
$url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
|
||||
$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
|
||||
foreach ( (array) $results as $result ) {
|
||||
$url = get_day_link($result->year, $result->month, $result->dayofmonth);
|
||||
$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
|
||||
$text = mysql2date($archive_day_date_format, $date);
|
||||
if ($show_post_count)
|
||||
$after = ' ('.$arcresult->posts.')'.$afterafter;
|
||||
$after = ' ('.$result->posts.')'.$afterafter;
|
||||
$output .= get_archives_link($url, $text, $format, $before, $after);
|
||||
}
|
||||
}
|
||||
} elseif ( 'weekly' == $type ) {
|
||||
$week = _wp_mysql_week( '`post_date`' );
|
||||
$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
|
||||
$key = md5($query);
|
||||
$cache = wp_cache_get( 'wp_get_archives' , 'general');
|
||||
if ( !isset( $cache[ $key ] ) ) {
|
||||
$arcresults = $wpdb->get_results($query);
|
||||
$cache[ $key ] = $arcresults;
|
||||
wp_cache_set( 'wp_get_archives', $cache, 'general' );
|
||||
} else {
|
||||
$arcresults = $cache[ $key ];
|
||||
$key = md5( $query );
|
||||
$key = "wp_get_archives:$key:$last_changed";
|
||||
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
||||
$results = $wpdb->get_results( $query );
|
||||
wp_cache_set( $key, $results, 'posts' );
|
||||
}
|
||||
$arc_w_last = '';
|
||||
$afterafter = $after;
|
||||
if ( $arcresults ) {
|
||||
foreach ( (array) $arcresults as $arcresult ) {
|
||||
if ( $arcresult->week != $arc_w_last ) {
|
||||
$arc_year = $arcresult->yr;
|
||||
$arc_w_last = $arcresult->week;
|
||||
$arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
|
||||
if ( $results ) {
|
||||
foreach ( (array) $results as $result ) {
|
||||
if ( $result->week != $arc_w_last ) {
|
||||
$arc_year = $result->yr;
|
||||
$arc_w_last = $result->week;
|
||||
$arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
|
||||
$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
|
||||
$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
|
||||
$url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
|
||||
$url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week);
|
||||
$text = $arc_week_start . $archive_week_separator . $arc_week_end;
|
||||
if ($show_post_count)
|
||||
$after = ' ('.$arcresult->posts.')'.$afterafter;
|
||||
$after = ' ('.$result->posts.')'.$afterafter;
|
||||
$output .= get_archives_link($url, $text, $format, $before, $after);
|
||||
}
|
||||
}
|
||||
|
@ -1016,23 +1010,20 @@ function wp_get_archives($args = '') {
|
|||
} elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
|
||||
$orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';
|
||||
$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
|
||||
$key = md5($query);
|
||||
$cache = wp_cache_get( 'wp_get_archives' , 'general');
|
||||
if ( !isset( $cache[ $key ] ) ) {
|
||||
$arcresults = $wpdb->get_results($query);
|
||||
$cache[ $key ] = $arcresults;
|
||||
wp_cache_set( 'wp_get_archives', $cache, 'general' );
|
||||
} else {
|
||||
$arcresults = $cache[ $key ];
|
||||
$key = md5( $query );
|
||||
$key = "wp_get_archives:$key:$last_changed";
|
||||
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
|
||||
$results = $wpdb->get_results( $query );
|
||||
wp_cache_set( $key, $results, 'posts' );
|
||||
}
|
||||
if ( $arcresults ) {
|
||||
foreach ( (array) $arcresults as $arcresult ) {
|
||||
if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
|
||||
$url = get_permalink( $arcresult );
|
||||
if ( $arcresult->post_title )
|
||||
$text = strip_tags( apply_filters( 'the_title', $arcresult->post_title, $arcresult->ID ) );
|
||||
if ( $results ) {
|
||||
foreach ( (array) $results as $result ) {
|
||||
if ( $result->post_date != '0000-00-00 00:00:00' ) {
|
||||
$url = get_permalink( $result );
|
||||
if ( $result->post_title )
|
||||
$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
|
||||
else
|
||||
$text = $arcresult->ID;
|
||||
$text = $result->ID;
|
||||
$output .= get_archives_link($url, $text, $format, $before, $after);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue