Make WordPress Core

Opened 3 months ago

Last modified 6 weeks 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.6 Priority: normal
Severity: normal Version: trunk
Component: I18N Keywords: has-patch
Focuses: performance Cc:


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 (8)

#1 @SergeyBiryukov
3 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.

3 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
3 months ago

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

#4 @aristath
3 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.

6 weeks ago

#6 @audrasjb
6 weeks ago

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

#7 @prbot
6 weeks 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
@@ @@

A similar upgrade routine was done in 4.0:

#8 @prbot
6 weeks ago

aristath commented on PR #476:

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

Note: See TracTickets for help on using tickets.