Making WordPress.org


Ignore:
Timestamp:
04/09/2020 06:54:12 AM (5 years ago)
Author:
dd32
Message:

Translate: Restore the Waiting Counts for Plugins/Themes as their own columns.

The column values are updated twice daily on a cron.

Fixes #3155.

File:
1 edited

Legend:

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

    r9018 r9711  
    1313 */
    1414class Stats extends GP_Route {
     15
     16    /**
     17     * Cache some expensive queries to be run on a Cron task.
     18     */
     19    public function cache_waiting_strings() {
     20        global $wpdb;
     21
     22        $cached_projects = [
     23            GP::$project->by_path( 'wp-plugins' ),
     24            GP::$project->by_path( 'wp-themes' ),
     25        ];
     26        $sql = "SELECT
     27                locale, locale_slug,
     28                SUM( stats.waiting ) + SUM( stats.fuzzy ) as waiting_strings
     29            FROM {$wpdb->project_translation_status} stats
     30                LEFT JOIN {$wpdb->gp_projects} p ON stats.project_id = p.id
     31            WHERE
     32                p.parent_project_id = %d
     33                AND p.active = 1
     34            GROUP BY locale, locale_slug";
     35
     36        foreach ( $cached_projects as $project ) {
     37            $rows = $wpdb->get_results( $wpdb->prepare( $sql, $project->id ) );
     38
     39            $cached_data = [];
     40            foreach ( $rows as $set ) {
     41                $locale_key = $set->locale;
     42                if ( 'default' != $set->locale_slug ) {
     43                    $locale_key = $set->locale . '/' . $set->locale_slug;
     44                }
     45   
     46                $cached_data[ $locale_key ] = (int) $set->waiting_strings;
     47            }
     48            $cached_data[ 'last_updated' ] = time();
     49
     50            update_option( __CLASS__ . '_cached_waiting_' . $project->slug, $cached_data, false );
     51        }
     52
     53    }
    1554
    1655    public function get_stats_overview() {
     
    2766            'apps/ios' => false,
    2867            'waiting' => false,
     68            'wp-themes' => false,
     69            'wp-plugins' => false,
    2970        );
    3071
     
    84125
    85126        // Append the Plugins/Themes waiting strings
    86         /*$parent_project_ids = implode(',', array(
    87             GP::$project->by_path( 'wp-plugins' )->id,
    88             GP::$project->by_path( 'wp-themes' )->id,
    89         ) );
    90         $sql = "SELECT
    91                 locale, locale_slug,
    92                 SUM( stats.waiting ) + SUM( stats.fuzzy ) as waiting_strings
    93             FROM {$wpdb->project_translation_status} stats
    94                 LEFT JOIN {$wpdb->gp_projects} p ON stats.project_id = p.id
    95             WHERE
    96                 p.parent_project_id IN ( $parent_project_ids )
    97                 AND p.active = 1
    98             GROUP BY locale, locale_slug";
    99 
    100         $rows = $wpdb->get_results( $sql );
    101         foreach ( $rows as $set ) {
    102             $locale_key = $set->locale;
    103             if ( 'default' != $set->locale_slug ) {
    104                 $locale_key = $set->locale . '/' . $set->locale_slug;
    105             }
    106 
    107             $translation_locale_statuses[ $locale_key ]['waiting'] += (int) $set->waiting_strings;
    108         }*/
     127        foreach ( [ 'wp-plugins', 'wp-themes' ] as $project_slug ) {
     128            $cached_data = get_option( __CLASS__ . '_cached_waiting_' . $project_slug, [] );
     129            $projects[ $project_slug ]->cache_last_updated = gmdate( 'Y-m-d H:i:s \U\T\C', $cached_data['last_updated'] );
     130            foreach ( $cached_data as $locale => $waiting ) {
     131                $translation_locale_statuses[ $locale ][ $project_slug ] = $waiting;
     132            }
     133        }
    109134
    110135        // Calculate a list of [Locale] = % subtotals
Note: See TracChangeset for help on using the changeset viewer.