Making WordPress.org

Changeset 9711


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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-overview.php

    r9618 r9711  
    1717                <?php foreach ( $projects as $slug => $project ) :
    1818                    $name = str_replace( array( 'WordPress.org ', 'WordPress for ', 'WordPress ', 'ectory', ' - Development' ), '', $project->name );
     19                    if ( $slug == 'wp-plugins' || $slug == 'wp-themes' ) {
     20                        $name = "Waiting $name";
     21                    }
    1922                    ?>
    2023                    <th class="col-<?php echo esc_attr( sanitize_title( $name ) ); ?>"><?php echo esc_html( $name ); ?></th>
     
    4750                            $percent = $translation_locale_statuses[ $locale_slug ][ $project->path ];
    4851
    49                             if ( 'waiting' === $project->path ) {
     52                            if ( 'waiting' === $project->path || 'wp-plugins' === $project->path || 'wp-themes' === $project->path ) {
     53                                $project_link_title = '';
     54                                if ( 'wp-plugins' === $project->path || 'wp-themes' === $project->path ) {
     55                                    $project_link_title = "Last Updated {$project->cache_last_updated}";
     56
     57                                    // Filter Plugins/Themes to Waiting (Most first) - Relying upon these being the last items.
     58                                    $projecturl = add_query_arg( 'filter', 'strings-waiting-and-fuzzy', $projecturl );
     59                                }
     60
    5061                                // Color code it on -0~500 waiting strings
    5162                                $percent_class = 100-min( (int) ( $percent / 50 ) * 10, 100 );
     
    5566                                }
    5667                                $percent_class = 'percent' . $percent_class;
    57                                 echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="'. esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . esc_url( $projecturl ) . '">' . number_format( $percent ) . '</a></td>';
     68                                echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="'. esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . esc_url( $projecturl ) . '" title="' . esc_attr( $project_link_title ) . '">' . number_format( $percent ) . '</a></td>';
    5869                            } else {
    5970                                $percent_class = 'percent' . (int) ( $percent / 10 ) * 10;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php

    r9616 r9711  
    4747
    4848        add_action( 'init', [ $this, 'respect_robots_txt' ], 9 );
     49
     50        add_action( 'init', [ $this, 'cron_tasks' ] );
    4951    }
    5052
     
    5860        // ?gp_route=robots.txt is here, as GlotPress ultimately is the router for the request.
    5961        add_rewrite_rule( '^robots\.txt$', 'index.php?robots=1&gp_route=robots.txt', 'top' );
     62    }
     63
     64    /**
     65     * Some pages rely upon a regular cron task to update the stats rather than live updates.
     66     */
     67    function cron_tasks() {
     68        if ( ! wp_next_scheduled ( 'wporg_gp_stats_cache_waiting_strings' ) ) {
     69            wp_schedule_event( time(), 'twicedaily', 'wporg_gp_stats_cache_waiting_strings' );
     70        }
     71        add_action( 'wporg_gp_stats_cache_waiting_strings', [ __NAMESPACE__ . '\Routes\Stats', 'cache_waiting_strings' ] );
    6072    }
    6173
  • 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.