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.

Files: 
CommentFileSizeAuthor
#10 1974630-10-file_entity-image_flush.patch1.65 KBszantog
PASSED: [[SimpleTest]]: [MySQL] 860 pass(es).
[ View ]
#8 1974630-file_entity-image_flush-7.patch1.65 KBhefox
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es).
[ View ]
#6 1974630-file_entity-image_flush-6.patch1.65 KBhefox
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/file_entity/file_entity.file.inc.
[ View ]
#1 file_entity-allow_disabling_on_image_flush_on_update-1974630-1.patch436 bytesesbenvb
PASSED: [[SimpleTest]]: [MySQL] 821 pass(es).
[ View ]

Comments

esbenvb’s picture

StatusFileSize
new436 bytes
PASSED: [[SimpleTest]]: [MySQL] 821 pass(es).
[ View ]

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
StatusFileSize
new1.65 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/file_entity/file_entity.file.inc.
[ View ]

Status:Needs review» Needs work

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

hefox’s picture

StatusFileSize
new1.65 KB
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es).
[ View ]

syntax error, sigh

This saves 4 seconds on save with amazons3 module :)

hefox’s picture

Status:Needs work» Needs review
szantog’s picture

StatusFileSize
new1.65 KB
PASSED: [[SimpleTest]]: [MySQL] 860 pass(es).
[ View ]

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().