Make WordPress Core


Ignore:
Timestamp:
05/29/2023 08:34:43 AM (3 years ago)
Author:
swissspidy
Message:

I18N: Improve _load_textdomain_just_in_time() logic when there are no translation files.

Fixes a performance issue where the JIT logic is invoked for every translation call if the there are no translations in the current locale. With this change, the information is cached by adding Noop_Translations instances to the global $l10n array. This way, get_translations_for_domain() returns earlier, thus avoiding subsequent _load_textdomain_just_in_time() calls.

Props swissspidy, johnbillion, ocean90.
Fixes #58321.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r55862 r55865  
    835835
    836836        if ( isset( $l10n[ $domain ] ) ) {
     837                if ( $l10n[ $domain ] instanceof NOOP_Translations ) {
     838                        unset( $l10n[ $domain ] );
     839
     840                        return false;
     841                }
     842
    837843                unset( $l10n[ $domain ] );
    838844
    … …  
    13081314        }
    13091315
     1316        $l10n[ $domain ] = &$noop_translations;
     1317
    13101318        return $noop_translations;
    13111319}
    … …  
    13231331function is_textdomain_loaded( $domain ) {
    13241332        global $l10n;
    1325         return isset( $l10n[ $domain ] );
     1333        return isset( $l10n[ $domain ] ) && ! $l10n[ $domain ] instanceof NOOP_Translations;
    13261334}
    13271335
Note: See TracChangeset for help on using the changeset viewer.