Skip to content

Conversation

sbruel
Copy link
Contributor

@sbruel sbruel commented Jul 8, 2025

Summary

The main change is to add an environment variable DISABLE_IMAGES_OUTPUT_STATIC_CACHE to skip the delivering of uploaded images through express-static-gzip if set to true.

Why do we need this?

In production, we have over 100k uploaded images mounted from a network drive.
On startup, express-static-gzip scans this folder to find gzipped versions of each image.
This can take multiple minutes on each startup.
There is no existing gzipped images in the folder, so this is completely unnecessary.

Why fix it like this?

This PR maintains the previous behavior if DISABLE_IMAGES_OUTPUT_STATIC_CACHE is not set.
An alternative would be to never use express-static-gzip for the image output folder.
The library does not compress the images, it only serves pre-compressed ones.

Provides a small layer on top of serve-static, which allows to serve pre-gzipped files

If this is the approach we prefer (it would simplify the code), it is easy to modify this PR, the added tests should make the behavior difference more obvious.

The original PR that introduced express-static-gzip likely for static assets only as there is no mechanism to automatically gzip uploaded images.
It included vite configuration code for assets

compression({
      verbose: true,
      disable: false,
      threshold: 10240, // compress files larger than 10KB
      algorithm: 'gzip',
      ext: '.gz',
    }),

that was updated in this PR.

Note: I will add the environment variable to the documentation once we decide on its necessity.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

Added extensive unit tests.

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.
  • A pull request for updating the documentation has been submitted.

@danny-avila danny-avila changed the base branch from main to dev July 8, 2025 18:54
@danny-avila
Copy link
Owner

Thanks! Does it make sense to default DISABLE_IMAGES_OUTPUT_STATIC_CACHE to true?

@sbruel
Copy link
Contributor Author

sbruel commented Jul 9, 2025

Does it make sense to default DISABLE_IMAGES_OUTPUT_STATIC_CACHE to true?

It does, but the behavior would be different from what we have now.
If we're fine with it I can change the name to something like ENABLE_IMAGES_OUTPUT_GZIP_SERVING to avoid having to set double negatives.

@sbruel
Copy link
Contributor Author

sbruel commented Jul 10, 2025

@danny-avila I changed the default in a new commit and updated the documentation.

@danny-avila danny-avila changed the title Fix scanning of the uploaded images folder on startup 🗂️ fix: Disable express-static-gzip for Uploaded Images Jul 11, 2025
@danny-avila danny-avila merged commit 9f44187 into danny-avila:dev Jul 11, 2025
5 checks passed
mohammadchehab pushed a commit to openbiocure/LibreChat that referenced this pull request Jul 13, 2025
…a#8307)

* Fix scanning of the uploaded images folder on startup

* Re-write tests to pass linting

* Disable image output gzip scan by default

* Add `ENABLE_IMAGE_OUTPUT_GZIP_SCAN` to `.env.example`
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Jul 15, 2025
…a#8307)

* Fix scanning of the uploaded images folder on startup

* Re-write tests to pass linting

* Disable image output gzip scan by default

* Add `ENABLE_IMAGE_OUTPUT_GZIP_SCAN` to `.env.example`
kenshinsamue pushed a commit to intelequia/LibreChat that referenced this pull request Aug 4, 2025
…a#8307)

* Fix scanning of the uploaded images folder on startup

* Re-write tests to pass linting

* Disable image output gzip scan by default

* Add `ENABLE_IMAGE_OUTPUT_GZIP_SCAN` to `.env.example`
xycjscs pushed a commit to xycjscs/LibreChat that referenced this pull request Aug 9, 2025
…a#8307)

* Fix scanning of the uploaded images folder on startup

* Re-write tests to pass linting

* Disable image output gzip scan by default

* Add `ENABLE_IMAGE_OUTPUT_GZIP_SCAN` to `.env.example`
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