Make MediaEntityMetadataWarmer non-optional #82
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.
I ran into am issue where my app started to throw errors during cache warming in production mode.
What happens is the following:
JoliCode\MediaBundle\Cache\MediaEntityMetadataWarmergets scheduled to warm up beforeDoctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer.During this warm-up phase the
MediaEntityMetadataWarmercalls$objectManager->getMetadataFactory()->getAllMetadata(), which effectively loads all entity metadata.A later point in time
DoctrineMetadataCacheWarmerstarts warming the cache, notices that the entity metadata has already been loaded and throws an Exception stating this should not be done.I'm not an expert at Symfony's internals by any means, but from what I've been able to reconstruct it seems to me that Symfony orders CacheWarmers both by priority and whether or not they are optional. As a result what appears to happen is the following:
MediaEntityMetadataWarmer).DoctrineMetadataCacheWarmer).So while
DoctrineMetadataCacheWarmerdoes have the highest priority, it still gets executed later, because it's part of the 2nd optional cycle, whereasMediaEntityMetadataWarmeris part of the preceding non-optional cycle.The easy fix appears to be to make
MediaEntityMetadataWarmeroptional as well. At first glance it does not appear to cause problems in my application, but since I'm not familiar with this part of Symfony at all I could be missing something important.Either way, here's a pull request with the easy fix. If I'm missing something important, please let me know.