image_file_delete() implements hook_file_delete(), which means it's called for every file deletion. However, not every file deletion is an image. It's currently calling the very expensive image_path_flush() anyway for every deletion.

It should somehow try to figure out whether this is an image (more specifically whether this is an imagefield).

/**
 * Implements hook_file_delete().
 */
function image_file_delete($file) {
  // Delete any image derivatives of this image.
  image_path_flush($file->uri);
}

Comments

aaron’s picture

i think it should check for any local image deletion, not just imagefields, because it's flushing derivatives, which could be for any local image. maybe we can check the mimetype?

maciej.zgadzaj’s picture

Version: 8.x-dev » 7.x-dev
Status: Active » Needs review
StatusFileSize
new473 bytes

No image_file_delete() in D8.

For D7 though, something like attached patch perhaps?

The last submitted patch, drupal-image_file_delete_flush_images_only-1238264-2.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.