element-api icon indicating copy to clipboard operation
element-api copied to clipboard

All requests blocked while generating image transforms

Open eablokker opened this issue 2 years ago • 0 comments

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

  • Craft version: 3.8.5
  • PHP version: 7.4.21
  • Database driver & version: MySQL 5.7.34
  • Plugins & versions: Element API 2.8.5

eablokker avatar Apr 25 '23 01:04 eablokker