extensions icon indicating copy to clipboard operation
extensions copied to clipboard

[storage-resize-images] The resize function is called twice for each uploaded image

Open yamankatby opened this issue 3 years ago • 2 comments

[REQUIRED] Step 2: Describe your configuration

  • Extension name: storage-resize-images
  • Extension version: 0.1.26

[REQUIRED] Step 3: Describe the problem

The resize function is called twice for each uploaded image.

Steps to reproduce:

  1. Install the extension with any configuration
  2. Upload an image to the storage
  3. The function will be triggered and it will resize the image and save it back to the storage successfully.
  4. The function will be triggered again (this time for the newly added resized image).
  5. The function will log File is already a resized image, no processing is required and will stop executing.

While this works totally and there are no errors or crashes, this causes a lot of unnecessary function calls. Imagine that I configure the extension to resize each image to multiple sizes (e.g. 200x200, 400x400, 800x800). This will cause 4 function calls for each image and 3 of them are unnecessary.

I suggest adding the ability to set different buckets for source and destination. That way I can create a separate bucket named images-to-resize for example, and the resized images will be stored in the other specified bucket.

Expected result

To trigger the resize function once for each image.

Actual result

The resize function is called multiple times for each image.

yamankatby avatar Mar 31 '22 07:03 yamankatby

I think this would be a good idea and pretty easy to implement with a new extension parameter that defaults to ${STORAGE_BUCKET}. I would like to give it a go in the next couple of weeks. I have a couple of questions though.

Should the resized images be placed at the same location in the new bucket? How should this interact with the RESIZED_IMAGES_PATH parameter then? If an image IMG.jpg is placed in bucket A location X, and has RESIZED_IMAGES_PATH="thumbnails". Should the new image go to bucket 'B' location 'X/thumbnails/IMG_200x200.jpg'? I feel like this would be the most reasonable behaviour. However for developers who already has installed the extension and who has customized the IMG_BUCKET parameter, this might not be desired as it breaks their application if they don't remember to set the new parameter too.

Another question, does anything else need to be changed in the extension.yaml in order for the extension to access a new bucket? I was looking at resources['generateResizedImage']['properties'] and saw a reference to the eventTrigger bucket - is something similar needed to open access to a new bucket?

emilbonnek avatar Jun 27 '22 09:06 emilbonnek

Reviewing this, although different source and destination buckets could be a nice feature, I think it's now the case that you can avoid the issue of extra function calls by specifying an INCLUDE_PATH_LIST or EXCLUDE_PATH_LIST.

Will keep the feature request open though, pending more interest.

cabljac avatar Sep 01 '23 13:09 cabljac