element-api
element-api copied to clipboard
All requests blocked while generating image transforms
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
- Use transforms in the element api
- 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)
]
];
}
- Request element from the API
- Wait long time for response as transforms are being generated
- 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
- Craft version: 3.8.5
- PHP version: 7.4.21
- Database driver & version: MySQL 5.7.34
- Plugins & versions: Element API 2.8.5