Skip to content
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

Feat/checksum media #139

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Feat/checksum media #139

wants to merge 22 commits into from

Conversation

gwillz
Copy link
Collaborator

@gwillz gwillz commented Feb 3, 2025

Our first foray into the media controller was perhaps naive. We quickly discovered poor cache invalidation and other architecture mistakes.

This cleans all of that up using a per-section checksum technique.

Gone are the days of "oh this site has cached assets from the previous deploy, that didn't happen on QA". The behaviour is now consistent and any caching controls only affects recalculation of checksums, which also naturally expire with a TTL.

Whereas before if the cache was not cleared - it could never expire. Sprout was also unable to intercept these requests because the URL was static and existing media was only served by nginx/apache. Changing the ?timestamp param cannot force a request through to Sprout.

When creating an media asset URL, Sprout will now create a checksum for the whole section directory (core, sprout, skin, or module). This serves as the cache-buster for browser caches. Upon deploying new files we get a new checksum.

There's also a general tidy up of some alternate formats for specifying media format. Sometimes we'd omit the /js|css/ directory or the modules/ prefix for a section. Somehow we thought we could reliably infer and fix if a skin URL was missing the subsite code. That's all standardised and documented in the Media helper now.

Key things

  • Media helper: in particular parse() and generateChecksum()
  • MediaController: the generate() and redirect() actions

Testing

Run the tests!

Also patch it into a Sprout 4 site and see how it goes. Edit some files, see the checksums change. Be sure to test for all media sections - core, sprout, skin, modules.

gwillz added 22 commits February 3, 2025 11:03
Only ever really used in tag().
This means we get to the real URL faster. With the current
nginx/apache rewrites we'll see a double redirect before we
get to the real file.
Now uses an parse -> instance -> action architecture.

Everything should read a bit easier now and we do less work (and it actually works).
Because we've dumped the output buffer, kohana will make a mess
after the method has finished.
@aitken85
Copy link
Collaborator

aitken85 commented Feb 4, 2025

Note on testing

% sites run composer test -- --filter MediaTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants