Making WordPress.org

Changeset 2280


Ignore:
Timestamp:
01/12/2016 05:44:47 PM (9 years ago)
Author:
ocean90
Message:

Translate: Cache the output of GP::$translation_set->existing_locales() for the locales overview.

The underlying query can take up to 3 seconds. :-(

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/cli/update-caches.php

    r2278 r2280  
    1111        $this->contributors_count();
    1212        $this->translation_status();
     13        $this->existing_locales();
    1314    }
    1415
     
    6869        WP_CLI::success( 'Translation status was updated.' );
    6970    }
     71
     72    /**
     73     * Update cache for existing locales.
     74     *
     75     * @subcommand existing-locales
     76     */
     77    public function existing_locales() {
     78        $existing_locales = GP::$translation_set->existing_locales();
     79
     80        wp_cache_set( 'existing-locales', $existing_locales, $this->cache_group );
     81        WP_CLI::success( 'Existing locales were updated.' );
     82    }
    7083}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/index.php

    r2109 r2280  
    77class WPorg_GP_Route_Index extends GP_Route {
    88
     9    private $cache_group = 'wporg-translate';
     10
    911    /**
    1012     * Prints all exisiting locales as cards.
     13     *
     14     * Note: Cache gets refreshed via `WPorg_GP_CLI_Update_Caches`.
    1115     */
    1216    public function get_locales() {
     17        $existing_locales = wp_cache_get( 'existing-locales', $this->cache_group );
     18        if ( false === $existing_locales ) {
     19            $existing_locales = array();
     20        }
     21
    1322        $locales = array();
    14         $existing_locales = GP::$translation_set->existing_locales();
    1523        foreach ( $existing_locales as $locale ) {
    1624            $locales[] = GP_Locales::by_slug( $locale );
     
    1927        unset( $existing_locales );
    2028
    21         $contributors_count = wp_cache_get( 'contributors-count', 'wporg-translate' );
     29        $contributors_count = wp_cache_get( 'contributors-count', $this->cache_group );
    2230        if ( false === $contributors_count ) {
    2331            $contributors_count = array();
    2432        }
    2533
    26         $translation_status = wp_cache_get( 'translation-status', 'wporg-translate' );
     34        $translation_status = wp_cache_get( 'translation-status', $this->cache_group );
    2735        if ( false === $translation_status ) {
    2836            $translation_status = array();
Note: See TracChangeset for help on using the changeset viewer.