Back

What is the best way to avoid an event triggering a function call

  • 0
  • Functions
Al
7 Aug, 2024, 12:55

Day 2 of trying Appwrite Functions 🙂

I have a function which monitors when a document is created or updated and then if media files information in a document field shows that thumbnails for media were not generated, it triggers thumbnail generation, stores them in Storage and then updates media files information (IDs in Storage).

I noticed that first run of the function triggers another run, which is while it's fast (3ms) can add up on large volumes of requests I think, so I'm wondering if there is a mechanism which allows to avoid triggering of an event when calling document update API from a function which uses server API or otherwise.

Even if I check x-appwrite-user-id for example (end function if it's empty) it still runs the function which has sharp/libvips & ffmpeg, so kinda expensive I think. Thanks.

BTW, I noticed a small bug in preview endpoint - it doesn't consider orientation of photos (previews are sideways when photos are displayed correctly in browsers/viewers which consider orientation) - I think appwrite uses sharp/libvips based on API parameter values for the endpoint, if so a simple additional .rotate() call without parameters when generating preview should fix this issue

TL;DR
Developers want to prevent a function from triggering itself while monitoring document creation or update. The function triggers thumbnail generation but ends up in a loop. They are seeking a mechanism to avoid this without impacting performance negatively due to high function runs. A potential bug in the preview endpoint is also noted, suggesting it may not account for photo orientations correctly. A solution proposed is to add a simple `.rotate()` call without parameters when generating previews to address this issue.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more