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

Skip compression of already compressed files #347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PetrDlouhy
Copy link

New take on #296

@lapinvert
Copy link

@evansd Any updates on this?

@PetrDlouhy
Copy link
Author

@lapinvert @adamchainz I have rebased this to the current main, but I am not sure if there is interest in getting this merged.
I expect that skipping already generated files (named with MD5 sums) would be only beneficial and speed things up for most people. But I can make this configurable (as default or non-default).

Also this would be very easily achieved when #354 is merged by simple Compressor override.

@lapinvert
Copy link

To me it sounds a no-brainer feature to have. For projects with many static files it makes a huge difference.

@@ -82,14 +82,14 @@ def compress(self, path):
stat_result = os.fstat(f.fileno())
data = f.read()
size = len(data)
if self.use_brotli:
if self.use_brotli and not os.path.isfile(f"{path}.br"):
Copy link
Contributor

@Archmonger Archmonger Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file names are only unique when using the CompressedManifestStaticFilesStorage backend.

When using the CompressedStaticFilesStorage backend, this would cause WhiteNoise to never re-compress a file, even if its contents have changed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. And unfortunately, in the default config, the non-MD5-hashed names are left around and can still be served... This needs some more involved consideration, and tests.

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.

4 participants