The file_entity module has a hook_file_update which flushes the image style cache every time a file entity is saved.

This will some times be overkill, so it should be possible to disable this behaviour.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

esbenvb’s picture

This patch allows you to se a variable, file_entity_update_disable_flush, when set to 1 the image style cache will not be flushed.

Important: when porting the patch, remember to to the correct attribution according to http://drupal.org/user/989064

Devin Carlson’s picture

Status: Needs review » Postponed (maintainer needs more info)

image_path_flush() clears any cached versions of a specific file in all image styles. It doesn't flush cached media for an entire style like image_style_flush(), so it actually provides a sort of performance benefit (since you don't have to flush an entire style cache/the entire image cache to see any changes).

Disabling this would cause confusion to users if they used the "file replace" functionality to replace an existing image with a new image but the old image continued to be displayed throughout the website. A similar issue has already been brought up over browser caching of images #1701924: Add a cache-busting string to images.

Do you have a use case for disabling per-file image style cache flushing? :)

esbenvb’s picture

Status: Postponed (maintainer needs more info) » Needs review

The problem is that all styled images for a particular file ID are deleted EVERY TIME i just add a tag or change the description of the image file...

Since we use remote storage, the causes operations to be much slower than they should - and we use the manualcrop module for cropping the images, which will delete the styled images when a new crop is made, so we don't really need file_entity to clear it as well...

I know that a lot of users will benefit from the default behavior of file_entity and that's why I added an option to toggle it instead of removing it.

Dave Reid’s picture

Status: Needs review » Needs work

Maybe we should more intelligently perform image_path_flush if $file->filesize != $file->original->filesize, which means the file *actually* changed.

Dave Reid’s picture

Actually might be nice to have a utility function to use here:

file_entity_has_file_changed($file, $original) {
return $file->filesize != $original->filesize || $file->uri != $original->uri;
}

hefox’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.65 KB

Status: Needs review » Needs work

The last submitted patch, 6: 1974630-file_entity-image_flush-6.patch, failed testing.

hefox’s picture

syntax error, sigh

This saves 4 seconds on save with amazons3 module :)

hefox’s picture

Status: Needs work » Needs review
szantog’s picture

Just rerolled the patch for testing.

szantog’s picture

Status: Needs review » Needs work
szantog’s picture

Status: Needs work » Reviewed & tested by the community

As I just rerolled the patch, I set it RTBC. Btw it works well.

This issue is major/critical if remote stream wrapper is used.

In our case when saving a node with 10-15 uploaded image. On the node form thumbnail image style is generated, then click on save, the generated images are flushed, however the only change of file is status to 1 at this point. Which means 20-30 api calls to amazons3.

Profiler said the 90% of runtime is file_entity_file_update. It's easy to run out of resources.

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/file_entity.pages.inc
@@ -443,6 +443,8 @@ function file_entity_add_upload_submit($form, &$form_state) {
+      $file->file_entity_skip_image_flush = TRUE;

I think we could skip this entirely if we check if empty($file->is_new))= in file_entity_has_file_changed().

geoffreyr’s picture

This patch is excellent, really saved my neck when I was working with RESTWS requests and finding that a simple PUT request to a file would take longer than five minutes to finish up. Reiterating @szantog's statement about it being essential when used with remote_stream_wrapper.

I've rerolled it against the latest DEV, with @Dave Reid's suggested change. I kept the check against $file->file_entity_skip_image_flush so one of our custom modules could fiddle it under the right circumstances.

  • joseph.olstad committed 6e4745a on 7.x-3.x authored by esbenvb
    Issue #1974630 by hefox, esbenvb, szantog, geoffreyr, Dave Reid, Devin...

  • joseph.olstad committed 3774370 on 7.x-2.x authored by esbenvb
    Issue #1974630 by hefox, esbenvb, szantog, geoffreyr, Dave Reid, Devin...
joseph.olstad’s picture

Looks like a good change, thanks for the re-roll and reporting.

joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.