Making WordPress.org


Ignore:
Timestamp:
03/29/2019 06:11:54 PM (7 years ago)
Author:
ocean90
Message:

Translate: Query existing locales for the homepage in a more performant way.

GP::$translation_set->existing_locales(); uses DISTINCT() on all translation sets which produces query timeouts. Instead, query only the existing locales of the main WordPress core project (wp/dev).

File:
1 edited

Legend:

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

    r8249 r8553  
    208208                        FROM {$wpdb->project_translation_status}
    209209                        WHERE `project_id` = %d AND `locale_slug` = %s",
    210                         2, 'default' // 2 = wp/dev
     210                        2, // 2 = wp/dev
     211                        'default'
    211212                ), OBJECT_K );
    212213
     
    228229                }
    229230
    230                 $locales   = GP::$translation_set->existing_locales();
     231                $locales   = $this->get_existing_locales();
    231232                $db_counts = $wpdb->get_results(
    232233                        "SELECT `locale`, COUNT( DISTINCT user_id ) as `count` FROM {$wpdb->user_translations_count} WHERE `accepted` > 0 GROUP BY `locale`",
     
    251252
    252253        /**
     254         * Retrieves existing locales of the main wp/dev project.
     255         *
     256         * Much faster alternative to `GP::$translation_set->existing_locales();` since it avoids
     257         * the expensive DISTINCT.
     258         *
     259         * @return array List of GlotPress locales.
     260         */
     261        private function get_existing_locales() {
     262                global $wpdb;
     263
     264                return $wpdb->get_col(
     265                        $wpdb->prepare(
     266                                "SELECT locale FROM {$wpdb->gp_translation_sets} WHERE `project_id` = %d and slug = %s",
     267                                2, // 2 = wp/dev
     268                                'default'
     269                        )
     270                );
     271        }
     272
     273        /**
    253274         * Updates cache for existing locales.
    254275         */
    255276        public function update_existing_locales_cache() {
    256                 $existing_locales = GP::$translation_set->existing_locales();
    257 
     277                $existing_locales = $this->get_existing_locales();
    258278                if ( ! $existing_locales ) {
    259279                        return;
Note: See TracChangeset for help on using the changeset viewer.