Making WordPress.org

Changeset 10442


Ignore:
Timestamp:
11/12/2020 06:20:16 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: i18n: Simplify the querying of the original strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r9017 r10442  
    176176
    177177        if ( false !== ( $originals = $this->cache_get( $slug, $branch, $cache_suffix ) ) ) {
     178            if ( isset( $originals[0] ) ) {
     179                // old cache style.
     180                foreach ( $originals as $i => $o ) {
     181                    $originals[ $o->id ] = $o->singular;
     182                    unset( $originals[ $i ] ); // Safe: Original IDs are huge for plugins.
     183                }
     184            }
     185
    178186            return $originals;
    179187        }
     
    186194
    187195        $originals = $wpdb->get_results( $wpdb->prepare(
    188             'SELECT id, singular, comment FROM ' . GLOTPRESS_TABLE_PREFIX . 'originals WHERE project_id = %d AND status = %s ORDER BY CHAR_LENGTH(singular) DESC',
     196            'SELECT id, singular FROM ' . GLOTPRESS_TABLE_PREFIX . 'originals WHERE project_id = %d AND status = %s ORDER BY CHAR_LENGTH(singular) DESC',
    189197            $branch_id, '+active'
    190         ) );
    191 
    192         if ( empty( $originals ) ) {
    193 
    194             // Still cache if empty, but as array, never false.
    195             $originals = array();
    196         }
     198        ), ARRAY_A );
     199
     200        $originals = array_column( $originals, 'singular', 'id' );
    197201
    198202        $this->cache_set( $slug, $branch, $originals, $cache_suffix );
     
    408412        // Sort the originals so as to process long strings first.
    409413        uasort( $originals, function( $a, $b ) {
    410             $a_len = strlen( $a->singular );
    411             $b_len = strlen( $b->singular );
     414            $a_len = strlen( $a );
     415            $b_len = strlen( $b );
    412416
    413417            return $a_len == $b_len ? 0 : ($a_len > $b_len ? -1 : 1);
     
    415419
    416420        // Mark each original for translation
    417         foreach ( $originals as $original ) {
    418             if ( ! empty( $original->id ) && array_key_exists( $original->id, $translations ) ) {
    419                 $content = $this->mark_gp_original( $original->id, $original->singular, $content );
     421        foreach ( $originals as $original_id => $original ) {
     422            if ( isset( $translations[ $original_id ] ) ) {
     423                $content = $this->mark_gp_original( $original_id, $original, $content );
    420424            }
    421425        }
Note: See TracChangeset for help on using the changeset viewer.