Make WordPress Core

Opened 12 months ago

Closed 3 months ago

Last modified 3 months ago

#59871 closed enhancement (fixed)

Prime further options in `wp_load_core_site_options()`

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch commit
Focuses: multisite, performance Cc:

Description

In Multisite, individual database queries are made to query a number of commonly used options.

On each request:

  • WPLANG
  • nonce_key
  • nonce_salt

On each authenticated request:

  • auth_key
  • auth_salt

The *_(salt|key) requests are only made if the constant is not defined or uses the default phrase put your unique phrase here.

Follow up to #56913.

Attachments (1)

Screenshot 2024-05-20 at 23.19.21.png (264.7 KB) - added by spacedmonkey 6 months ago.

Download all attachments as: .zip

Change History (27)

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


12 months ago

#2 @joemcgill
12 months ago

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

Thanks @peterwilsoncc. Moving to Future Release for now with needs-patch. This seems like it could be a good-first-bug candidate. Do you have ideas about the implementation that you'd want to share?

This ticket was mentioned in PR #6588 on WordPress/wordpress-develop by @spacedmonkey.


6 months ago
#3

  • Keywords has-patch added; needs-patch removed

Requires #61053.

Use wp_prime_site_option_caches to prime option / network option caches if not defined as const.

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

#4 follow-up: @spacedmonkey
6 months ago

I have put together a PR for this that uses wp_prime_site_option_caches. I think this a little cleaner solution.

@peterwilsoncc commented on PR #6588:


6 months ago
#5

@spacedmonkey It looks like you accidentally pushed to the WordPress org's copy of the repo. Are you able to reopen from your fork so the branch doesn't get deleted when the bots sync every minute or so.

#6 in reply to: ↑ 4 @peterwilsoncc
6 months ago

Replying to spacedmonkey:

I have put together a PR for this that uses wp_prime_site_option_caches. I think this a little cleaner solution.

Yes, that's much cleaner.

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


6 months ago

This ticket was mentioned in PR #6597 on WordPress/wordpress-develop by @spacedmonkey.


6 months ago
#8

Requires #61053.

Use wp_prime_site_option_caches to prime option / network option caches if not defined as const.

@spacedmonkey commented on PR #6588:


6 months ago
#9

@spacedmonkey It looks like you accidentally pushed to the WordPress org's copy of the repo. Are you able to reopen from your fork so the branch doesn't get deleted when the bots sync every minute or so.

Done https://github.com/WordPress/wordpress-develop/pull/6597

#10 @spacedmonkey
6 months ago

  • Milestone changed from Future Release to 6.6

Testing instruction:

Comment / remove out the following files of wp-config.php

define( 'AUTH_KEY',          '#O9e87Y5ebxFl6M-TN9Q$~|r|`0$qlc=-dDwRgh6(ol9pAAGL?V5Z& M!4CPSY[(' );
define( 'SECURE_AUTH_KEY',   'l49R6x5DzDOx%sF#JVu*V-bpg4|!<G<M,|V[gwUFZ@4(CSHC.fv7^oXt!-U2N-fo' );
define( 'LOGGED_IN_KEY',     ']k]@J3Gn&v~CCC|c5;<9F.R@X-g~u`tfMV9xRg9F:WzQHUOy3,?|c:h6=FQB,z^[' );
define( 'NONCE_KEY',         'kT{LWm&zB,I`R3WgecY(ih?g{Mpu[M?dy._vfwN8 a?+cGAt~|o!|zUtLG~2H<oY' );
define( 'AUTH_SALT',         'B;q9^gGo;*|z^)M7()=<+0BHoP?s3fs4<6sGCmTDNvC@*[>[RFbD]dOk@ZHXI&R@' );
define( 'SECURE_AUTH_SALT',  'Z*FMM?m<x!6?E~%r_j>HPDxC/^W-7%(T}}*;zEzi9Qzm?HE=XL1L7)0Layb<Y~`F' );
define( 'LOGGED_IN_SALT',    'MCNC|L[^rD&9J`+dR1m;geR%0:N:F>x FU1;)dmt,_Y+.4G7dE.dakBwq4r0knx#' );
define( 'NONCE_SALT',        'bij7+;xA87bL~2w=+N5&eo1RH]hFN>o<S>M0&uH8K2~] g~F#aA_<D;Q01k8O;ig' );

Load a home page.
Use query monito to see the call to wp_prime_network_option_caches in wp_salt.

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


6 months ago

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


5 months ago

This ticket was mentioned in PR #6720 on WordPress/wordpress-develop by @peterwilsoncc.


5 months ago
#13

Use the wp_prime_site_option_caches() function to prime options containing the various salts in a single database query.

I'd really like to add some tests for these but am not able to as the salts are cached in a static withing wp_salt and by the time the test is run they will have been added to the static elsewhere.

https://github.com/WordPress/wordpress-develop/blob/5706a203849740ab4479136e5fd22803f942f5ef/src/wp-includes/pluggable.php#L2425-L2437

I did test these locally with the code in this gist and it worked as expected when running the following commands:

./vendor/bin/phpunit --filter Tests_Pluggable_wp_salt -c tests/phpunit/multisite.xml
./vendor/bin/phpunit --filter Tests_Pluggable_wp_salt

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

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


5 months ago

#16 @spacedmonkey
5 months ago

  • Owner set to peterwilsoncc
  • Status changed from new to assigned

#17 @peterwilsoncc
5 months ago

  • Milestone changed from 6.6 to 6.7
  • Type changed from defect (bug) to enhancement

As getting the salt options works just fine, I think this is an enhancement rather than a bug. This ticket doesn't fix anything, it just makes it a little nicer.

As I've missed the 6.6 Beta, I'll move this to the 6.7 milestone.

Sorry I forgot to set the type correctly when opening the ticket.

This ticket was mentioned in Slack in #core-performance by peterwilsoncc. View the logs.


5 months ago

@peterwilsoncc commented on PR #6720:


4 months ago
#19

@spacedmonkey I've pushed a change to also prime the secret_key option if we're priming other options. It's not generally used as best I can tell (only if the scheme is invalid).

#20 @spacedmonkey
3 months ago

  • Keywords commit added

@peterwilsoncc This is good to commit.

#21 @peterwilsoncc
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58837:

Options, Meta APIs: Prime salts when stored in database.

For salts generated and stored in the database, use wp_prime_site_option_caches() within wp_salt() to prime the options in a single database query, down from up to nine database queries.

The options are primed when the corresponding constant is either undefined or uses the default string put your unique phrase here.

Props joemcgill, spacedmonkey, peterwilsoncc.
Fixes #59871.

#24 @kebbet
3 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for fixing some typos introduced in r58837.

#25 @SergeyBiryukov
3 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 58838:

Docs: Correct some typos in a comment in wp_salt().

Follow-up to [58837].

Props kebbet.
Fixes #59871.

@SergeyBiryukov commented on PR #7126:


3 months ago
#26

Thanks for the PR! Merged in r58838.

Note: See TracTickets for help on using tickets.