Making WordPress.org


Ignore:
Timestamp:
01/25/2018 05:24:19 PM (9 years ago)
Author:
obenland
Message:

Plugins: Cut down on translation queries.

Queries all translations for a plugin at once and then checks against the results.

File:
1 edited

Legend:

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

    r6287 r6428  
    376376                }
    377377
     378                $raw_translations = $wpdb->get_results( $wpdb->prepare(
     379                        'SELECT original_id, translation_0 FROM ' . GLOTPRESS_TABLE_PREFIX . 'translations WHERE original_id IN (' . implode( ', ', wp_list_pluck( $originals, 'id' ) ) . ') AND translation_set_id = %d AND status = %s',
     380                        $translation_set_id, 'current'
     381                ) );
     382
     383                $translations = [];
     384                foreach ( $raw_translations as $translation ) {
     385                        $translations[ $translation->original_id ] = $translation->translation_0;
     386                }
     387
    378388                foreach ( $originals as $original ) {
    379                         if ( empty( $original->id ) ) {
    380                                 continue;
     389                        if ( ! empty( $original->id ) && array_key_exists( $original->id, $translations ) ) {
     390                                $content = $this->translate_gp_original( $original->singular, $translation[ $original->id ], $content );
    381391                        }
    382 
    383                         $translation = $wpdb->get_var( $wpdb->prepare(
    384                                 'SELECT translation_0 FROM ' . GLOTPRESS_TABLE_PREFIX . 'translations WHERE original_id = %d AND translation_set_id = %d AND status = %s',
    385                                 $original->id, $translation_set_id, 'current'
    386                         ) );
    387 
    388                         if ( empty( $translation ) ) {
    389                                 continue;
    390                         }
    391 
    392                         $content = $this->translate_gp_original( $original->singular, $translation, $content );
    393392                }
    394393
Note: See TracChangeset for help on using the changeset viewer.