Making WordPress.org


Ignore:
Timestamp:
09/17/2015 03:05:18 AM (9 years ago)
Author:
dd32
Message:

Translate: Update the Project Stats plugin to store data in an easier to parse format.

  • Stores a Locale + Locale slug (ie. en-au/default) rather than a translation set id
  • Projects now include their sub-projects in their counts. A project no longer has to have sets directly on it for it's status to be queried.
  • Updates the Stats overview to take advantage of these optimizations.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-stats-overview.php

    r1861 r1881  
    4444        }
    4545
    46         $all_project_ids = $sql_cases = array();
    47         foreach ( $projects as $slug => &$project ) {
    48             $project_ids = array();
     46        // Load the projects for each display item
     47        array_walk( $projects, function( &$project, $project_slug ) {
    4948            if ( ! $project ) {
    50                 $project = GP::$project->by_path( $slug );
     49                $project = GP::$project->by_path( $project_slug );
    5150            }
    52             $project_ids[] = $project->id;
     51        } );
    5352
    54             foreach ( $project->inclusive_sub_projects() as $sub ) {
    55                 if ( $sub->active ) {
    56                     $project_ids[] = $sub->id;
    57                 }
    58             }
    59             unset( $sub );
    60 
    61             $project_id_list = implode( ', ', array_map( 'intval', $project_ids ) );
    62             $sql_cases[] = $gpdb->prepare( "WHEN ts.project_id IN( $project_id_list ) THEN %s", $slug );
    63 
    64             $all_project_ids = array_merge( $all_project_ids, $project_ids );
    65         }
    66         unset( $slug, $project_ids, $subs, $project );
    67 
    68         $sql_cases = implode( "\n", $sql_cases );
    69         $all_project_ids = implode( ', ', array_map( 'intval', $all_project_ids ) );
    70 
     53        $all_project_paths_sql = '"' . implode( '", "', array_keys( $projects ) ) . '"';
    7154        $sql = "SELECT
    72                 CASE
    73                     $sql_cases
    74                 END as project_slug,
    75                 s.locale as locale,
    76                 s.slug as locale_slug,
    77                 (100 * SUM(ts.current)/SUM(ts.all)) as percent_complete
    78             FROM translate_project_translation_status ts
    79                 LEFT JOIN translate_translation_sets s ON ts.project_id = s.project_id AND ts.translation_set_id = s.id
     55                path, locale, locale_slug,
     56                (100 * stats.current/stats.all) as percent_complete
     57            FROM {$gpdb->prefix}project_translation_status stats
     58                LEFT JOIN {$gpdb->prefix}projects p ON stats.project_id = p.id
    8059            WHERE
    81                 ts.project_id IN ( $all_project_ids )
    82             GROUP BY project_slug, s.locale, s.slug";
     60                p.path IN ( $all_project_paths_sql )";
    8361
    8462        $rows = $gpdb->get_results( $sql );
     
    9169                $locale_key = $set->locale . '/' . $set->locale_slug;
    9270            }
    93             $translation_locale_statuses[ $locale_key ][ $set->project_slug ] = floor( (float) $set->percent_complete );
     71            $translation_locale_statuses[ $locale_key ][ $set->path ] = floor( (float) $set->percent_complete );
    9472        }
    9573        unset( $rows, $locale_key, $set );
Note: See TracChangeset for help on using the changeset viewer.