craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

All requests blocked while generating image transforms #178

Open eablokker opened 1 year ago

eablokker commented 1 year ago

Description

When using image transforms in the element api, all other requests to the website are blocked until all image transforms are finished generating.

Steps to reproduce

  1. Use transforms in the element api
  2. Make sure transformed images haven't been created yet
$images = [];
foreach ($entry->images as $asset) {
    $images[] = [
        'title' => $asset->title,
        'url' => $asset->getUrl($customAssetTransform_1),
        'sizes' => [
            $asset->getUrl($customAssetTransform_2),
            $asset->getUrl($customAssetTransform_3)
        ]
    ];
}
  1. Request element from the API
  2. Wait long time for response as transforms are being generated
  3. Try to access website while waiting

Suggest returning transform creation URLs in the first response and not caching the response. Wait to cache the response until a request is made when all the images have been created and their actual URLs can be returned. Similar to Craft's Twig {% cache %} tag.

Additional info