Making WordPress.org

Changeset 15257


Ignore:
Timestamp:
10/01/2026 02:51:52 PM (30 hours ago)
Author:
obenland
Message:

Translate Bridge: Hash cache keys and use inner joins for translation lookups.

Props timse201.
Closes ​https://github.com/WordPress/wordpress.org/pull/943.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/glotpress-translate-bridge/glotpress-translate-bridge.php

    r10312 r15257  
    33 * Plugin Name: GlotPress Translate Bridge
    44 * Description: This plugin allows for a code to translate arbitrary strings from a GlotPress instance for the current locale.
    5  * Version: 0.1
     5 * Version: 0.2
    66 * Plugin URI: https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/glotpress-translate-bridge/
    77 * Author: wordpressdotorg
    … …  
    131131                $sql_locale = $wpdb->prepare( "s.locale = %s AND s.slug = %s", $locale['locale'], $locale['slug'] );
    132132
     133                // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Dynamic table prefix cannot be passed via placeholders.
    133134                $translation = $wpdb->get_row(
    134135                        "SELECT t.translation_0, t.translation_1, t.translation_2, t.translation_3, t.translation_4, t.translation_5
    135136                                FROM {$this->gp_prefix}projects p
    136                                 LEFT JOIN {$this->gp_prefix}originals o ON p.id = o.project_id
    137                                 LEFT JOIN {$this->gp_prefix}translation_sets s ON p.id = s.project_id
    138                                 LEFT JOIN {$this->gp_prefix}translations t ON t.original_id = o.id AND t.translation_set_id = s.id
     137                                INNER JOIN {$this->gp_prefix}originals o ON p.id = o.project_id
     138                                INNER JOIN {$this->gp_prefix}translation_sets s ON p.id = s.project_id
     139                                INNER JOIN {$this->gp_prefix}translations t ON t.original_id = o.id AND t.translation_set_id = s.id
    139140
    140141                        WHERE
    … …  
    147148                        ARRAY_N
    148149                );
     150                // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    149151
    150152                if ( ! $translation ) {
    … …  
    219221         * @return string The cache key.
    220222         */
    221         private function cache_key( $strings, $project_path ) {
    222                 return strtolower( get_locale() ) . ':' . $project_path . ':' . serialize( array_filter( $strings ) );
     223        private function cache_key( array $strings, $project_path ) {
     224                $payload = serialize( array_filter( $strings ) );
     225                return 'gp_tb:' . strtolower( get_locale() ) . ':' . md5( $project_path . ':' . $payload );
    223226        }
    224227}
Note: See TracChangeset for help on using the changeset viewer.