WordPress.org

Make WordPress Core

Changeset 18228


Ignore:
Timestamp:
06/10/2011 06:31:39 AM (8 years ago)
Author:
dd32
Message:

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

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r18150 r18228  
    10321032function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
    10331033    $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
     1034    $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
    10341035
    10351036    if ( empty($check_urls) ) {
    10361037        $widgets = get_option( 'dashboard_widget_options' );
    1037         if ( empty($widgets[$widget_id]['url']) ) {
     1038        if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
    10381039            echo $loading;
    10391040            return false;
     
    10421043    }
    10431044
    1044     include_once ABSPATH . WPINC . '/class-feed.php';
    1045     foreach ( $check_urls as $check_url ) {
    1046         $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
    1047         if ( ! $cache->load() ) {
    1048             echo $loading;
    1049             return false;
    1050         }
     1045    $cache_key = 'dash_' . md5( $callback . implode(',', $check_urls) );
     1046    if ( false !== ( $output = get_transient( $cache_key ) ) ) {
     1047        echo $output;
     1048        return true;
     1049    }
     1050
     1051    if ( ! $doing_ajax ) {
     1052        echo $loading;
     1053        return false;
    10511054    }
    10521055
     
    10541057        $args = array_slice( func_get_args(), 2 );
    10551058        array_unshift( $args, $widget_id );
     1059        ob_start();
    10561060        call_user_func_array( $callback, $args );
     1061        set_transient( $cache_key, ob_get_flush(), 43200); // Default lifetime in cache of 12 hours (same as the feeds)     
    10571062    }
    10581063
  • trunk/wp-admin/index-extra.php

    r17743 r18228  
    66 * @subpackage Administration
    77 */
     8
     9define('DOING_AJAX', true);
    810
    911/** Load WordPress Bootstrap */
     
    1921
    2022case 'dashboard_incoming_links' :
    21     wp_dashboard_incoming_links_output();
     23    wp_dashboard_incoming_links();
    2224    break;
    2325
    2426case 'dashboard_primary' :
    25     wp_dashboard_rss_output( 'dashboard_primary' );
     27    wp_dashboard_primary();
    2628    break;
    2729
    2830case 'dashboard_secondary' :
    29     wp_dashboard_secondary_output();
     31    wp_dashboard_secondary();
    3032    break;
    3133
    3234case 'dashboard_plugins' :
    33     wp_dashboard_plugins_output();
     35    wp_dashboard_plugins();
    3436    break;
    3537
Note: See TracChangeset for help on using the changeset viewer.