Skip to content

Commit

Permalink
Merge pull request #4624 from neos/bugfix/batch-load-thumbnails-for-a…
Browse files Browse the repository at this point in the history
…sset

BUGFIX: Load all thumbnails for an asset to skip further requests
  • Loading branch information
Sebobo authored Oct 17, 2023
2 parents 115030e + 71aaba7 commit db63fe0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Neos.Media/Classes/Domain/Model/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,9 @@ public function refresh()
{
$this->generatorStrategy->refresh($this);
}

public function getConfigurationHash(): string
{
return $this->configurationHash;
}
}
12 changes: 10 additions & 2 deletions Neos.Media/Classes/Domain/Service/ThumbnailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,16 @@ public function getThumbnail(AssetInterface $asset, ThumbnailConfiguration $conf
if (isset($this->thumbnailCache[$assetIdentifier][$configurationHash])) {
$thumbnail = $this->thumbnailCache[$assetIdentifier][$configurationHash];
} else {
$thumbnail = $this->thumbnailRepository->findOneByAssetAndThumbnailConfiguration($asset, $configuration);
$this->thumbnailCache[$assetIdentifier][$configurationHash] = $thumbnail;
$thumbnail = null;
// Load all thumbnails for the asset and cache them to prevent further db requests for the same asset
$thumbnailsForAsset = $this->thumbnailRepository->findByOriginalAsset($asset);
/** @var Thumbnail $thumbnailVariant */
foreach ($thumbnailsForAsset as $thumbnailVariant) {
$this->thumbnailCache[$assetIdentifier][$thumbnailVariant->getConfigurationHash()] = $thumbnailVariant;
if ($thumbnailVariant->getConfigurationHash() === $configurationHash) {
$thumbnail = $thumbnailVariant;
}
}
}
$async = $configuration->isAsync();
if ($thumbnail === null) {
Expand Down

0 comments on commit db63fe0

Please sign in to comment.