Making WordPress.org

Changeset 1782


Ignore:
Timestamp:
07/23/2015 08:08:28 PM (9 years ago)
Author:
ocean90
Message:

Translate: Loop over locales instead of grouping them in SQL.

see #994.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/cli/wporg-update-cached-data.php

    r1530 r1782  
    99    public $cache_group = 'wporg-translate';
    1010
     11    private $locales = array();
     12
    1113    public function run() {
     14        $this->locales = GP::$translation_set->existing_locales();
     15
    1216        $this->update_contributors_count();
    1317        $this->update_translation_status();
     
    2024        global $gpdb;
    2125
    22         $results = $gpdb->get_results( "
    23             SELECT ts.locale, COUNT( DISTINCT( t.user_id ) ) AS count
    24             FROM $gpdb->translations t
    25                 INNER JOIN $gpdb->translation_sets AS ts
    26                     ON ts.id = t.translation_set_id
    27             WHERE
    28                 ( t.status = 'current' || t.status = 'old' )
    29                 AND t.user_id IS NOT NULL
    30                 AND t.user_id <> '0'
    31             GROUP BY ts.locale
    32         " );
     26        $counts = array();
     27        foreach ( $this->locales as $locale ) {
     28            $result = $gpdb->get_var( $gpdb->prepare( "
     29                SELECT COUNT( DISTINCT( t.user_id ) ) AS count
     30                FROM {$gpdb->translations} t
     31                    INNER JOIN {$gpdb->translation_sets} AS ts
     32                        ON ts.id = t.translation_set_id
     33                WHERE
     34                    ( t.status = 'current' || t.status = 'old' )
     35                    AND t.user_id IS NOT NULL
     36                    AND t.user_id <> '0'
     37                    AND ts.locale = %s
     38            ",  $locale ) );
    3339
    34         $counts = array();
    35         if ( $results ) {
    36             foreach ( $results as $result ) {
    37                 $counts[ $result->locale ] = $result->count;
     40            if ( $result ) {
     41                $counts[ $locale ] = $result;
     42            } else {
     43                $counts[ $locale ] = 0;
    3844            }
    3945        }
     
    4854        global $gpdb;
    4955
    50         $locales = GP::$translation_set->existing_locales();
    5156        $projects = GP::$project->many( "
    5257            SELECT *
    53             FROM $gpdb->projects
     58            FROM {$gpdb->projects}
    5459            WHERE
    5560                path LIKE 'wp/dev%'
     
    5863        $translation_status = array();
    5964        foreach ( $projects as $project ) {
    60             foreach ( $locales as $locale ) {
     65            foreach ( $this->locales as $locale ) {
    6166                $set = GP::$translation_set->by_project_id_slug_and_locale(
    6267                    $project->id,
Note: See TracChangeset for help on using the changeset viewer.