Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wp_prime_network_option_caches function in option.php #6311

Closed

Conversation

spacedmonkey
Copy link
Member

@spacedmonkey spacedmonkey commented Mar 22, 2024

Introduced the new function wp_prime_network_option_caches in option.php. This function simplifies the handling of network option caches, enhancing the speed of operations. In the wp_load_core_site_options function, removed cache processing code and replaced it with a call to the new function. These changes improve code efficiency and readability.

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Introduced the new function wp_prime_network_option_caches in option.php. This function simplifies the handling of network option caches, enhancing the speed of operations. In the wp_load_core_site_options function, removed cache processing code and replaced it with a call to the new function. These changes improve code efficiency and readability.
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

jonnynews and others added 9 commits April 22, 2024 18:13
The commit adds more sophisticated logic in the site options cache. It not only fetches and caches the options, but also identifies and caches those options that were not found ('notoptions'). Only when 'notoptions' cache has been modified, does it update this cache, thus optimizing efficiency.
This commit simplifies the caching logic in the wp_prime_network_option_caches function. It uses the cache_keys array as a map instead of a simple list, allowing us to avoid duplicate attempts to generate cache keys. A $cache_group variable is also introduced to replace hard-coded 'site-options' string, enhancing code readability and maintenance.
The code has been updated to sort post types before the cache key generation to ensure consistency. Also, a default orderby value of 'date' has been added for the same purpose. Changes have been tested by adding a new test case to verify the query cache for differently ordered post types.
This commit adds several unit tests for the wp_prime_network_option_caches method in WordPress. Specifically, it includes tests for priming multiple options, handling a mix of primed and unprimed options, and tests related to prime options on a different network.
This commit introduces 'WPLANG' to the array of core options in the 'option.php' file. This ensures that the language setting for Wordpress is included in the list of options that are cached for network use.
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few notes inline. This seems to be testing well but I think the code needs a little tidying up.

src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
Added multisite support to wpPrimeNetworkOptionCaches tests by separately setting up cache groups for multisite and single site. Also included additional checks for option caching in multisite setup.
@spacedmonkey spacedmonkey marked this pull request as ready for review May 13, 2024 09:28
Copy link

github-actions bot commented May 13, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props spacedmonkey, peterwilsoncc, mukesh27, joemcgill.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

spacedmonkey and others added 3 commits May 13, 2024 10:38
The cache key generation and deletion stages have been refactored in the test scripts. Instead of repeating the same logic to generate cache keys, a separate code block defines all the cache keys up front. This change simplifies cache deletion and read operations, making the test scripts cleaner and easier to understand.
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source changes look good to me, a couple more notes in the tests.

Otherwise, the only question that remains is whether we should also add wp_prime_site_option_caches as a wrapper similar to all the other site/network option functions.

My inclination is to do so.

tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
This commit refactors the option caching functions in the WordPress source code for efficiency. It reorders the functions and renames wp_prime_network_option_caches to wp_prime_site_option_caches to enhance clarity. The update ensures optimal caching of network options with a single database query, which significantly increases performance.
This commit adds an optional network_id parameter to the wp_prime_network_option_caches function in the options.php file. This offers the flexibility of specifying a network ID when priming network option caches, defaulting to the current network ID if none is provided.
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things that need tidying up before it's commit ready.

src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Outdated Show resolved Hide resolved
tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php Outdated Show resolved Hide resolved
spacedmonkey and others added 2 commits May 18, 2024 09:47
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
In the PHPUnit test file for priming network options, the alignment of the equals (=) operator in variable assignments has been made consistent. This applies to the declarations of `$network_id` and `$cache_key`, improving readability and adherence to code style guidelines.
@spacedmonkey
Copy link
Member Author

Amazing feedback @peterwilsoncc . It is really appricated. Your best code review! Legend.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of notes. Great work here!

src/wp-includes/option.php Outdated Show resolved Hide resolved
src/wp-includes/option.php Show resolved Hide resolved
The function wp_prime_network_option_caches() was updated to no longer allow a null value for the $network_id parameter. A validity check for the $network_id parameter was also added. If the parameter is not a number, the function will return early.
@spacedmonkey
Copy link
Member Author

Thanks for the feedback @joemcgill . Actioned feedback.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks pretty good. One more small suggestion, but pre-approving since you addressed my main concern.

src/wp-includes/option.php Show resolved Hide resolved
src/wp-includes/option.php Show resolved Hide resolved
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left feedback inline. Approving since using null is consistent with how get_site_option() was previously impelmented.

src/wp-includes/option.php Show resolved Hide resolved
@spacedmonkey
Copy link
Member Author

Committed 6662cb0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants