Cache the Dashboard RSS Widgets HTML output to reduce the memory footprint of including SimplePie. Fixes #16927

git-svn-id: http://svn.automattic.com/wordpress/trunk@18228 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2011-06-10 06:31:39 +00:00
parent bf9c99e1fa
commit 5df56d4bba
2 changed files with 19 additions and 12 deletions

View File

@ -1031,29 +1031,34 @@ function wp_dashboard_plugins_output() {
*/
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
$doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
if ( empty($check_urls) ) {
$widgets = get_option( 'dashboard_widget_options' );
if ( empty($widgets[$widget_id]['url']) ) {
if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
echo $loading;
return false;
}
$check_urls = array( $widgets[$widget_id]['url'] );
}
include_once ABSPATH . WPINC . '/class-feed.php';
foreach ( $check_urls as $check_url ) {
$cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
if ( ! $cache->load() ) {
echo $loading;
return false;
}
$cache_key = 'dash_' . md5( $callback . implode(',', $check_urls) );
if ( false !== ( $output = get_transient( $cache_key ) ) ) {
echo $output;
return true;
}
if ( ! $doing_ajax ) {
echo $loading;
return false;
}
if ( $callback && is_callable( $callback ) ) {
$args = array_slice( func_get_args(), 2 );
array_unshift( $args, $widget_id );
ob_start();
call_user_func_array( $callback, $args );
set_transient( $cache_key, ob_get_flush(), 43200); // Default lifetime in cache of 12 hours (same as the feeds)
}
return true;

View File

@ -6,6 +6,8 @@
* @subpackage Administration
*/
define('DOING_AJAX', true);
/** Load WordPress Bootstrap */
require_once( './admin.php' );
@ -18,19 +20,19 @@ send_nosniff_header();
switch ( $_GET['jax'] ) {
case 'dashboard_incoming_links' :
wp_dashboard_incoming_links_output();
wp_dashboard_incoming_links();
break;
case 'dashboard_primary' :
wp_dashboard_rss_output( 'dashboard_primary' );
wp_dashboard_primary();
break;
case 'dashboard_secondary' :
wp_dashboard_secondary_output();
wp_dashboard_secondary();
break;
case 'dashboard_plugins' :
wp_dashboard_plugins_output();
wp_dashboard_plugins();
break;
}