WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 2 months ago

#50980 reviewing defect (bug)

Extra query to get WPLANG option on each page-load when the option doesn't exist in the db

Reported by: aristath Owned by: SergeyBiryukov
Milestone: 5.7 Priority: normal
Severity: normal Version: 5.0
Component: I18N Keywords: has-patch
Focuses: performance Cc:

Description

On each page-load we call determine_locale() which in turn tries to get the WPLANG option using get_option.
When the site language is en_US and has never been changed, the WPLANG option doesn't exist in the options table in the database.
As a result, get_option doesn’t find it autoloaded and then triggers a query.

If the language is changed to something else and then back to en_US, the option is saved as an empty string and gets autoloaded.

Proposed solution:
The simplest solution that comes to mind (which also wouldn't interfere with the way multilingual plugins work) would be to check if the row exists in the table, and if not just create it and save as empty string. It can then get picked-up by the object-caches and spare us the extra query.

Change History (11)

#1 @SergeyBiryukov
5 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.6

This can be done in an upgrade routine like upgrade_550(), for example.

This ticket was mentioned in PR #476 on WordPress/wordpress-develop by aristath.


5 months ago

  • Keywords has-patch added; needs-patch removed

Adds a default value for WPLANG on new installations and introduces a new upgrade routine for WP 5.6.0.

Trac ticket: https://core.trac.wordpress.org/ticket/50980

#3 @SergeyBiryukov
5 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @aristath
5 months ago

Just a note here: I noticed that all upgrade processes mention database-versions and that's how things get triggered.
I don't know how these get generated or what the db-version will be in order to add that in the patch, is there documentation somewhere about that?

This ticket was mentioned in Slack in #core by justinahinon. View the logs.


4 months ago

#6 @audrasjb
4 months ago

Just added a comment in the PR about a very small WPCS point

#7 @prbot
4 months ago

ocean90 commented on PR #476:

The current test failure is valid and needs to be investigated:

1) Tests_L10n_GetLocale::test_network_option_should_be_fallback_on_multisite
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'es_ES'
+'en_US'
/var/www/tests/phpunit/tests/l10n/getLocale.php:54

A similar upgrade routine was done in 4.0:
https://github.com/WordPress/wordpress-develop/blob/c7f5af72dcc4f36365656fdbfccfa0fb51fefd1f/src/wp-admin/includes/upgrade.php#L1921-L1933

#8 @prbot
4 months ago

aristath commented on PR #476:

Failing tests were fixed.
Tested on single-site and multisite installations :+1:

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


2 months ago

#10 @SergeyBiryukov
2 months ago

  • Milestone changed from 5.6 to 5.7

It looks like the tests are still failing with the latest patch, so this needs some more work:
https://travis-ci.com/github/WordPress/wordpress-develop/jobs/386888985

With 5.6 RC in a few days, moving to the next release for now.

#11 @hellofromTonya
2 months ago

  • Version changed from trunk to 5.0
Note: See TracTickets for help on using tickets.