Making WordPress.org

Changeset 9018


Ignore:
Timestamp:
07/02/2019 07:41:56 AM (6 years ago)
Author:
dd32
Message:

Translate: Stats overview: Cache a failure to fetch the top plugins/themes to prevent endless requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php

    r8256 r9018  
    152152            // Fetch top 100 plugins..
    153153            $items = get_transient( __METHOD__ . '_plugin_items' );
    154             if ( ! $items ) {
     154            if ( false === $items ) {
    155155                $api = wp_safe_remote_get( 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[per_page]=250' );
     156                $items = array();
    156157                foreach ( json_decode( wp_remote_retrieve_body( $api ) )->plugins as $plugin ) {
    157158                    $items[ $plugin->slug ] = (object) [
     
    159160                    ];
    160161                }
    161                 set_transient( __METHOD__ . '_plugin_items', $items, DAY_IN_SECONDS );
     162                set_transient( __METHOD__ . '_plugin_items', $items, $items ? DAY_IN_SECONDS : 5 * MINUTE_IN_SECONDS );
    162163            }
    163164        } elseif ( 'themes' == $view && defined( 'WPORG_THEME_DIRECTORY_BLOGID' ) ) {
    164165            $items = get_transient( __METHOD__ . '_theme_items' );
    165             if ( ! $items ) {
     166            if ( false === $items ) {
    166167                // The Themes API API isn't playing nice.. Easiest way..
    167168                switch_to_blog( WPORG_THEME_DIRECTORY_BLOGID );
     
    179180                    unset( $items[$slug]->slug );
    180181                }
    181                 set_transient( __METHOD__ . '_theme_items', $items, DAY_IN_SECONDS );
     182                set_transient( __METHOD__ . '_theme_items', $items, $items ? DAY_IN_SECONDS : 5 * MINUTE_IN_SECONDS );
    182183            }
    183184        } else {
Note: See TracChangeset for help on using the changeset viewer.