From 5df56d4bba2c4d416b681e4bb9ee67d6fc025977 Mon Sep 17 00:00:00 2001 From: dd32 Date: Fri, 10 Jun 2011 06:31:39 +0000 Subject: [PATCH] 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 --- wp-admin/includes/dashboard.php | 21 +++++++++++++-------- wp-admin/index-extra.php | 10 ++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 988cf43b9..ead81f2fa 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -1031,29 +1031,34 @@ function wp_dashboard_plugins_output() { */ function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) { $loading = '

' . __( 'Loading…' ) . '

' . __( 'This widget requires JavaScript.' ) . '

'; + $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; diff --git a/wp-admin/index-extra.php b/wp-admin/index-extra.php index c197bfd77..bbaea63e5 100644 --- a/wp-admin/index-extra.php +++ b/wp-admin/index-extra.php @@ -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; }