Repository navigation
Store the options read on every request autoloaded - #207
Merged
Merged
Conversation
The seven options primed at the start of a request were stored with autoload off or did not exist, so without a persistent object cache the priming query ran on every request. The small options are now written autoloaded, the two page options without an autoload value so that WordPress decides by size, and an inactive prerender feature state stays as an empty array. The 7.7.14 migration switches existing rows and stores every missing option with the value its reader falls back to. The populate state is not autoloaded with a persistent object cache, where it is written too often for that. Closes inline0#204.
Contributor
|
Merged and released in Blockstudio 7.7.14, integration commit 823a2fd. The integration additionally migrates page-option autoload metadata without deleting values, reevaluates the size policy when configurations grow or shrink, and runs migrations for late-loaded theme Composer packages. Regression coverage includes those paths, option query counts, and persistent-cache behavior. Full CI and distribution checks pass. Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #204.
Since 7.7.6 one
wp_prime_option_caches()call loads the seven options Blockstudio reads on every request. Without a persistent object cache that query still ran on every request, because the options were stored with autoload off or did not exist. With this change a migrated site has all seven among the autoloaded options, so priming returns before the query.What changes
blockstudio_build_lock_cleanup_version,blockstudio_collection_post_types_signaturefalsetrueblockstudio_populate_cache_versionfalsetrue,falsewith a persistent object cacheblockstudio_pages_collection_manifests,blockstudio_pages_template_forfalsewp_max_autoloaded_option_sizeblockstudio_static_prerender_feature_stateThe migration
7.7.14does the one-time part: it switches the small existing rows withwp_set_options_autoload(), adds the two page options again so that WordPress decides by size, and stores every option that does not exist yet. First activation stores them as well. The priming call stays as the fallback for what is still not autoloaded.Where this differs from the proposal in #204
blockstudio_pages_template_foronly exists after an explicit page sync,blockstudio_populate_cache_versiononly after a content write with populate blocks, and the cleanup version not at all withcache/enabledoff. One missing row is enough to keep the query. So the migration stores all seven, each with the value its reader already uses as the default (array(),'','0'), which reads the same as no option.trueinstead ofnull. They are a version string, a hash and a three-key array and cannot grow. Withnull,update_option()runs an extraSELECT autoloadon every write to re-evaluate the size.Build_Cache::autoload_populate_state()). It is written on every content change, and each write of an autoloaded option replaces the whole cachedalloptionsentry. Such a site has the option in its object cache anyway and gains nothing from autoloading it.wp_set_options_autoload()can only storeonoroff, andonwould switch off the size check for exactly the two rows that can get large.delete_option()plusadd_option()storesauto, as for a new row, and later writes keep re-evaluating it. Between the two calls a parallel request sees no row once: it reads no templates for that request and rescans the manifests.reconcile_feature_state()stored nothing for an inactive site and deleted the row when a feature was switched off, so it was missing on most sites. It now stores an empty array in that case, which is what the read falls back to.deactivate()still deletes it. Two assertions that expected the option to be gone after a switch-off now expect the empty array.Notes
7.7.14, the next version according to the open release branch. It has to carry the version this ships in.Migrateruns onplugins_loaded. When Blockstudio is loaded after that hook has fired, from a theme's Composer autoload, the callback is never called, as today for the 7.6.6 migration. Those sites keep the one query, nothing else changes for them. I can send a separate pull request that lets the migrations run in that case, if you want that.MigrateTestexpectedblockstudio_settingsnot to exist after a migration; it now exists as an empty array. Both readers useget_option( 'blockstudio_settings', array() ).Tests
OptionCachePrimingTest: with all seven options missing, one query (the fallback, as before). After the migration, a request reads all of them without any option query, and again after every writer has stored a real value. With a persistent object cache the populate state is not autoloaded.MigrateTest: existing rows with autoload off are autoloaded afterwards with their values intact, in the caches of the running request and for a new request. A 200 KB template option stays out of the autoloaded options. Missing options are stored with their read defaults. Existing settings are kept. First activation stores the options.main, the new priming test and the new and changedMigrateTestcases fail; with the change they pass.tests/unit/runtime,build,pagesandsettings. Those four directories give the same results with and without the change, apart from the two changed assertions inruntime. PHPCS and PHPStan are clean on the changed files. The full suites are left to CI as per AGENTS.md.