-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add wp_prime_network_option_caches function in option.php #6311
Conversation
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.
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
There was a problem hiding this 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.
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.
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 Unlinked AccountsThe 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:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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>
There was a problem hiding this 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.
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.
There was a problem hiding this 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.
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.
Amazing feedback @peterwilsoncc . It is really appricated. Your best code review! Legend. |
There was a problem hiding this 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!
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.
Thanks for the feedback @joemcgill . Actioned feedback. |
There was a problem hiding this 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.
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
There was a problem hiding this 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.
Committed 6662cb0 |
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.