Make WordPress Core

Ticket #8781: 8781.2.patch

File 8781.2.patch, 4.9 KB (added by Viper007Bond, 13 years ago)

Cache slugs, avoid using get_plugins() on every page load

  • wp-admin/includes/dashboard.php

     
    708708        $new     = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
    709709        $updated = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
    710710
     711        $plugin_slugs = get_option( 'plugin_slugs' );
     712        if ( !is_array($plugin_slugs) ) {
     713                $all_plugins = get_plugins();
     714                $plugin_slugs = array();
     715                foreach ( $all_plugins as $slug => $plugin )
     716                        $plugin_slugs[] = $slug;
     717                update_option( 'plugin_slugs', $plugin_slugs );
     718        }
     719
    711720        foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
    712721                if ( !isset($$feed->items) || 0 == count($$feed->items) )
    713722                        continue;
    714723
    715724                $$feed->items = array_slice($$feed->items, 0, 5);
    716                 $item_key = array_rand($$feed->items);
    717725
     726                // Pick a random, non-installed plugin
     727                $loop = true;
     728                while ( true == $loop ) {
     729                        $item_key = array_rand($$feed->items);
     730                        $item = $$feed->items[$item_key];
     731
     732                        list($link, $frag) = explode( '#', $item['link'] );
     733
     734                        $link = clean_url($link);
     735                        if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
     736                                $slug = $matches[1];
     737                        else
     738                                $slug = '';
     739
     740                        // Check to see if this random plugin is already installed. If so, try a different one.
     741                        reset( $plugin_slugs );
     742                        foreach ( $plugin_slugs as $plugin_slug ) {
     743                                if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
     744                                        unset( $$feed->items[$item_key] );
     745                                        continue 2;
     746                                }
     747                        }
     748
     749                        // We can stop looping as this random plugin isn't installed
     750                        $loop = false;
     751                }
     752
    718753                // Eliminate some common badly formed plugin descriptions
    719754                while ( ( null !== $item_key = array_rand($$feed->items) ) && false !== strpos( $$feed->items[$item_key]['description'], 'Plugin Name:' ) )
    720755                        unset($$feed->items[$item_key]);
     
    722757                if ( !isset($$feed->items[$item_key]) )
    723758                        continue;
    724759
    725                 $item = $$feed->items[$item_key];
    726 
    727760                // current bbPress feed item titles are: user on "topic title"
    728761                if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) )
    729762                        $title = $matches[1];
     
    733766
    734767                $description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) );
    735768
    736                 list($link, $frag) = explode( '#', $item['link'] );
    737 
    738                 $link = clean_url($link);
    739                 if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
    740                         $slug = $matches[1];
    741                 else
    742                         $slug = '';
    743 
    744769                $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
    745770                                                        '&TB_iframe=true&width=600&height=800';
    746771
  • wp-admin/includes/schema.php

     
    302302        add_option('update_core', array());
    303303        add_option('dismissed_update_core', array());
    304304
     305        // 2.7.1
     306        add_option('plugin_slugs', '');
     307
    305308        // Delete unused options
    306309        $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
    307310        foreach ($unusedoptions as $option) :
  • wp-admin/plugins.php

     
    213213$recent_plugins = array();
    214214$recently_activated = (array) get_option('recently_activated');
    215215
    216 //Clean out any plugins which were deactivated over a week ago.
     216// Update the slug cache
     217$plugin_slugs = array();
     218foreach ( $plugin_slugs as $slug => $plugin )
     219        $plugin_slugs[] = $slug;
     220update_option( 'plugin_slugs', $plugin_slugs );
     221
     222// Clean out any plugins which were deactivated over a week ago.
    217223foreach ( $recently_activated as $key => $time )
    218224        if ( $time + (7*24*60*60) < time() ) //1 week
    219225                unset($recently_activated[ $key ]);