-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[AssetMapper][FrameworkBundle] Add cache warmer for AssetMapper compilation #59089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AssetMapper][FrameworkBundle] Add cache warmer for AssetMapper compilation #59089
Conversation
alexandre-daubois
commented
Dec 4, 2024
Q | A |
---|---|
Branch? | 7.3 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | Fix #59072 |
License | MIT |
9a6f721
to
e6c0090
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we need two cache warmers: one for debug and one for no-debug (prod)?
the one for debug should remove files, so that the assets can be served dynamically
* @author Ryan Weaver <ryan@symfonycasts.com> | ||
* @author Alexandre Daubois <alex.daubois@gmail.com> | ||
*/ | ||
final class AssetMapperCompileCacheWarmer implements CacheWarmerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssetMapperCacheWarmer (same in the changelog)
Should we keep one warmer but inject |
e6c0090
to
5587c5c
Compare
This would mean creating (or even keeping) services for nothing. Not sure it'd be easier to maintain also. |
Oh, by "the one for debug should remove files", you mean "remove files and nothing else"? If yes, indeed two warmers are more relevant, I'l do the change. |
Like in #59073 yes |
5587c5c
to
9657b3e
Compare
Second cache warmer added! |
* @author Ryan Weaver <ryan@symfonycasts.com> | ||
* @author Alexandre Daubois <alex.daubois@gmail.com> | ||
*/ | ||
final class AssetMapperCacheWarmer implements CacheWarmerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warmer seems to have a lot in common with the CompileCommand (logically 😅 ) ... should we not try to keep that code in one place only ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be better indeed! However, the command outputs a lot of useful info through console's OutputInterface (which the warmer doesn't have access to). We could create a service containing the logic, with an optional OutputInterface. Not sure it worth it given the warmer in pretty concise?
$entrypointFiles[$entrypointName] = $path; | ||
} | ||
|
||
$this->eventDispatcher?->dispatch(new PreAssetsCompileEvent(new NullOutput())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will all services / listeners be available during Cache Warm ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! You'll be able to register your event listeners just as you do normally 🙂
$this->compiledConfigReader->removeConfig(AssetMapper::MANIFEST_FILE_NAME); | ||
$this->compiledConfigReader->removeConfig(ImportMapGenerator::IMPORT_MAP_CACHE_FILENAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can anyone disable this cache warmer ? As it destroys data and people have many reasons to separate cache warm and asset build, this feels more than required
(sorry if i missread something here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have better knowledge of this component than me 🙂 How would you like to opt-in/out from this warmer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it optional to start, so that cache:clear does not force all assets (images, videos, idk.. to be read in memory).
And i realize this is the reason for this architeccture at first. I remember asking about the config files beeing outside, and i think the answer was to make this independant from the php code.
So, we must have a way (even, the default way i'd say for BC reasons) to build a Symfony app without deleting all its asset config.
Ok so definitively we should not do this (or exactly like this). AssetMapper generates during They are not just cache files, as without it in production the assets won't be served. But it wont be possible to rebuild them with this warmer if some cache:clear is executed (so massive BC break already). Also these files are not in the cache directory, but in the public/assets directory.. that it self may not be available or writable then. Some binary may also not be available in production (Sass and/or Typescript users are not a minority), so the recompilation of assets won't be possible there. |
If I understand correctly, do you advise to not have this cache warmer at all? |
After chatting on Slack, what @smnandre means is that in prod mode, the cache warmer will try to compile the assets, which can break, because the preconditions to compile them might not be met (tyically because the assets where compiled ahead of deployment, in a container that doesn't have the required binaries). This is a concern we should address indeed. Running cache:clear in prod mode shouldn't be destructive as it is now. |
Using a cache warmer instead of a manual or explicit “compile” command would be potentially destructive on three levels and useless on one. DestructiveDeletion of Critical Files Risk to Asset Integrity Fallback to Raw Source Assets Useless Heavy Resource ConsumerResource-Intensive Redundant Caching Efforts I now strongly believe that, today, a cache warmer (in production) introduces far more problems than it solves. (P.S. I asked GPT for help to fix my English.. as it seems I have real difficulties expressing my thoughts and being understood these days.) |
I don't think the issue is with using a cache warmer on its own. But the implementation of the cache warmer needs to be carefully designed to handle these aspects you raised. |
Well i'm less and less sure about that to be honest.. As the cache has not much role to play once in production. So there is no real reason to "warm" anything here but there is to ... (not nitpicking) .... "build". But more generally: of course, it's an AssetMapper / assets "problem" more than a "cache" one... There are multiple things we should/need to improve on that side:
I also think we need some other changes/improvments (not strictly related to this particular implementation, but somehow addressing the same topic)
But I think all this requires time and some form of coordination.. Also, i need to say out loud that despite the impression this discussion may give, i'd love to have a real "zero-build" mode available and i'd be the first one to enable it... on my personal projects ;) |
Let me close as objections are valid IMHO. We need to figure out another approach... |