Image style flush takes long for many images

Created on 4 September 2023, 10 months ago
Updated 27 May 2024, about 1 month ago

Image style flush takes very long time for big folders. In our case image styles folder contains 40GB and it takes more than 1 hours to flush image style. This leads to problem: when there is an image style is change, config import will take very long time. This may lead to a long downtime during deployment.

Background:

Image style flush deletes the folder with images. Every image will be re-generated on demand later by Drupal. But in case of S3 this process takes very long because 1) S3 deletion takes longer 2) s3fs_files table should be updated 3) Drupal cache should be cleared.

There are a couple of solutions, that I could propose:

Solution 1:

Replace image flush with a custom implementation, that will do the flush in a batch or a cron queue, so that the deployment process does not take too long.

Solution 2:

Override the way how the image styles flush works in Drupal core (\Drupal\image\Entity\ImageStyle::flush).
Instead of recursively deleting every file, we could execute rmdir and delete s3fs_file records with a LIKE condition: DELETE * FROM s3fs_file WHERE uri = "public://styles/{imagestyle_name}%"

✨ Feature request
Status

Active

Version

4.0

Component

Code

Created by

🇦🇹Austria a.milkovsky UTC +2

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024