Repository navigation
Cache aggregated store scopes configuration (#41730) - #41733
Open
lbajsarowicz wants to merge 1 commit into
Open
lbajsarowicz wants to merge 1 commit into
lbajsarowicz wants to merge 1 commit into
Conversation
Scopes read store_website, store_group and store on every request because the aggregated scopes data was only memoized per instance. Warm requests now read it from the config cache; data built without a database or without runtime scope rows is never cached, and existing store, group and website tag cleaning invalidates the entry.
|
Hi @lbajsarowicz. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
Author
|
@magento run all tests |
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.
Description (*)
Magento\Store\App\Config\Type\Scopes::get()keeps the scopes data (websites, store groups, store views) only in an instance property. The first call of every request reads its source,scopesConfigSourceAggregated, whoseRuntimeConfigSourcerunsSELECT *onstore_website,store_groupandstore. The first caller isStoreManager::getStore()whileHttp::launch()builds the session config, before the built-in full page cache is checked. So every storefront, GraphQL and REST request and every built-in FPC hit pays three queries.app:config:dump scopesdoes not help: the aggregated source still reads the runtime DB source.Scopesnow stores the aggregated data in theconfigcache type, serialized with the core serializer and taggedstore,store_groupandwebsite.StoreManager::reinitStores()cleans the config cache bystore_relations,store,websiteandstore_groupafter store save, group save/delete and website create/delete. Store delete cleans the config cache.AbstractModel::cleanModelCache()cleans the entity tag on every save.cache:clean configandcache:flushremove the entry too.Scopes::clean()still resets only the in-memory data.App\Config::clean()runs on every admin config save and on application-server reload, and must not drop the shared entry.RuntimeConfigSourcegets two small public methods,isDbAvailable()andhasRuntimeData(). It also implementsResetAfterRequestInterface, asScopesnow does.Measured on a clean 2.4-develop install with warm caches, before the change: a built-in FPC hit ran 4 queries, 3 of them these selects;
/customer/account/login/ran 10, with the same 3. With the change, the integration test shows a freshScopesinstance on a warm cache running no queries.Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
/twice (built-in FPCHIT) and/customer/account/login/.SELECT store_website.*,SELECT store_group.*andSELECT store.*. After: none of them on warm requests.bin/magento cache:clean config: the next request reads the three tables once and caches them again.Questions or comments
All new constructor arguments are optional, with an ObjectManager fallback. No
di.xmlchange.Store, group and website changes written with raw SQL (for example in a data patch) are not seen until the next config cache clean.
setup:upgradeandsetup:installclean caches. This matches the other store data already kept in the config cache (StoreManager's stores data).Tests: unit tests for
Scopes(cache hit and miss, tags, no-DB bypass, no caching without runtime data, memory-onlyclean()) andRuntimeConfigSource. New integration testMagento\Store\App\Config\Type\ScopesTest: a freshScopesinstance with a warm cache runs zero queries; store view save/delete, store group rename, existing website update and config cache clean each invalidate the cached entry. Locally: unit, PHPStan, the static (LiveCodeTest) suite and the integration test pass.Contribution checklist (*)