Repository navigation
Cache successful deployment configuration checks (#41731) - #41732
Open
lbajsarowicz wants to merge 1 commit into
Open
lbajsarowicz wants to merge 1 commit into
lbajsarowicz wants to merge 1 commit into
Conversation
ConfigChangeDetector loaded the config_hash flag on every request that reached the front controller. A successful check is now cached under a key derived from the generated section hashes, and Hash::regenerate() cleans those entries, so a changed or reverted configuration still throws.
|
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\Deploy\Model\Plugin\ConfigChangeDetector::beforeDispatch()runs on every request that reaches the front controller (frontend, adminhtml, GraphQL, REST). Each run callsChangeDetector::hasChanges(), which loads the storedconfig_hashflag from theflagtable. In practice the stored hashes almost never change between requests, but the query runs every time.The plugin now caches a successful check in the config cache type. The cache key is derived from the freshly generated hashes of the importer sections. If
config.phporenv.phpis edited, the generated hashes change, the key misses, and the existing database comparison runs and throws as before.Hash::regenerate()(run byapp:config:importandsetup:upgrade) cleans the cached entries after it saves new hashes. Without that, a sequence of "A in sync → import B → restore A without import" would still hit A's old entry. The clean runs after the flag is saved, outside the existingtryblock, so a cache backend error is not reported as "The hash isn't saved."ChangeDetectoritself is unchanged, so CLI commands (app:config:status,app:config:import,config:set --lock-*) compare against the database exactly as before.DbStatusValidator, the siblingbeforeDispatchcheck, already caches its result the same way (db_is_up_to_date).Measured on a clean 2.4-develop install: every uncached request (page, GraphQL, REST, admin) loses one
SELECT flag.* FROM flag WHERE flag_code='config_hash'once the cache is warm.Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
/customer/account/login/) and a GraphQLstoreConfigquery.SELECT flag.* FROM flag WHERE flag_code='config_hash'. After: only the first request after a cache clean runs it.systemsection ofapp/etc/config.phpwithout runningapp:config:import: the next request throws "The configuration file has changed. Run the "app:config:import" or the "setup:upgrade" command to synchronize the configuration."bin/magento app:config:import; requests work again. Restore the previousconfig.phpwithout importing: the next request throws again.Questions or comments
Both new constructor arguments are optional, with an ObjectManager fallback. With
deployment/blue_green/enabledthe plugin returns early, as before.The cached entry lives until the next config cache clean or
Hash::regenerate(). Multi-node installs need a shared cache backend for the regenerate clean to reach every node, which Magento already requires for the config cache. A stored hash changed directly in the database (for example a DB restore) is noticed after the next cache flush.Tests: unit tests for the plugin (warm cache skips
Hash::get(), in-sync result cached, changed configuration not cached and still throws, blue/green bypass) and forHash(clean after a successful save, no clean when the save fails). New integration testMagento\Deploy\Model\Plugin\ConfigChangeDetectorTestwith the real config cache: noflagselect on a warm request, and the A → B → A sequence throws. Locally: unit, PHPStan, the static (LiveCodeTest) suite and the integration test pass; the warm-cache integration test fails without the plugin change.Contribution checklist (*)