Repository navigation
Features: Preload the options experiments read on every request - #1119
Conversation
Markdown Feeds and Key Encryption each read a flag option on every request (wpai_markdown_feeds_flush_rewrite on wp_loaded and wpai_key_encryption_resume_migration on init). Both flags are deleted after use, so they are missing most of the time and cost one query each on sites without a persistent object cache, even after WordPress#1113 made the feature toggles a single query. Abstract_Feature::get_preloaded_options() lets a feature list the options it reads on every request. The Loader adds them to the toggle names it passes to wp_prime_option_caches(), so all of them come from the same query. Markdown Feeds and Key Encryption return their flag from it.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1119 +/- ##
==========================================
Coverage 81.61% 81.62%
- Complexity 3083 3088 +5
==========================================
Files 129 129
Lines 12289 12297 +8
==========================================
+ Hits 10030 10037 +7
- Misses 2259 2260 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Darin Kotter <darin.kotter@gmail.com>
|
Thanks for the fixes. Noted for the next ones: |
What?
Follow up to #1113. See #1112.
Loads the two options that experiments read on every request together with the feature toggles, so all of them come from one query instead of three.
Why?
#1113 loads the 21 feature toggles with one query. Two more options were still looked up one by one on every request:
wpai_markdown_feeds_flush_rewrite(Markdown Feeds reads it onwp_loaded) andwpai_key_encryption_resume_migration(Key Encryption reads it oninit). Both are flags that are deleted after use, so they are missing most of the time, and a missing option costs a query on every request on sites without a persistent object cache. Asked for as a new PR in #1113.How?
Abstract_Feature::get_preloaded_options()is new. It returns the names of options a feature reads on every request, empty by default.Markdown_FeedsandKey_Encryptionreturn their flag from it.wp_prime_option_caches()in the same call. A laterget_option()of a flag is served from the cache, whether the row exists or not, so the flags are consumed exactly as before.get_preloaded_options(). Features that do not define it are skipped, the same optional-method patternSettings_Registrationuses forregister_settings().Queries per request on a fresh install with nothing switched on (MariaDB 12.3.3, WordPress 7.1.2, no persistent object cache,
developalready has #1113):develop/?rest_route=/)wp-login.phpadmin-ajax.phpwp-cron.phpSame 2 fewer queries on SQLite with WordPress 7.1. Against 1.4.0 the home page goes from 47 to 25 queries.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Implementation, tests, measurements, and PR wording. I reviewed the reasoning and test results, and I take responsibility for the contribution.
Testing Instructions
wp-content/mu-plugins/count-ai-option-queries.php.developthe log line shows 2 single lookups forwpai_options. With this PR it shows 0./feed/markdown/. It shows the feed, so the flush flag was still read and consumed. Switch it off and the feed is a 404 again.Automated:
npm run test:php -- --filter 'test_preloaded_options|test_get_preloaded_options_defaults_to_empty'runs the four new tests. All four fail ondevelop(three undefined method errors, one query count) and pass here.composer lintand PHPStan pass.Changelog Entry