-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Update compiled views only if they actually changed #55450
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
Update compiled views only if they actually changed #55450
Conversation
663fa79
to
fe0de84
Compare
When running in a read-only filesystem container with views pre-cached at build time, Laravel checks if the cached view's timestamp is older than the source's to decide when to recompile. This is fine as long as we do not make OCI image builds reproducible. If we do however, the timestamps match (because timestamps of all files are set to 01.01.1970), so Laravel recompiles the view, tries to write to a read-only filesystem and the container crashes. This patch computes SHA256 hashes over existing and newly compiled file contents, compares those and writes only if the file actually changes.
fe0de84
to
5f39764
Compare
Now with proper Unit tests. \o/ |
Never mind, figure out already. It only checks the hash when it needs to compile. In other words, after checking for the timestamp. |
return; | ||
} | ||
|
||
$contentHash = hash('sha256', $contents); |
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.
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.
xxh128 seems like a better choice. I will change it.
Yeah, could use xxh128 since we're using that in other areas. |
Sorry, I was on vacation. Actually, I realized that this effectively defeats the purpose of view caching as every view is compiled every time it is accessed. I noticed the |
When running in a read-only filesystem container with views pre-cached at build time, Laravel checks if the cached view's timestamp is older than the source's to decide when to recompile. This is fine as long as we do not make OCI image builds reproducible.
If we do however, the timestamps match (because timestamps of all files are set to 01.01.1970), so Laravel recompiles the view, tries to write to a read-only filesystem and the container crashes.
This patch computes SHA256 hashes over existing and newly compiled file contents, compares those and writes only if the file actually changes.