Skip to content

Commit 7acea0a

Browse files
committed
Fix #163 and #159: remove fileExists check; catch UnableToRetrieveMetadata
fileExists() on a cloud filesystem (e.g. S3) makes an HTTP HEAD request on every uncached component fetch, adding latency proportional to file count. Remove the existence check and widen the catch around create() to include UnableToRetrieveMetadata (thrown by fileSize()/mimeType() when the file is absent). This also fixes #159: manifest fetches no longer 500 in offline environments where cloud-hosted files are unreachable during development.
1 parent 94d2762 commit 7acea0a

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

src/Factory/Uploadable/MediaObjectFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Persistence\ManagerRegistry;
1616
use League\Flysystem\Filesystem;
1717
use League\Flysystem\UnableToReadFile;
18+
use League\Flysystem\UnableToRetrieveMetadata;
1819
use Liip\ImagineBundle\Service\FilterService;
1920
use Silverback\ApiComponentsBundle\Annotation\UploadableField;
2021
use Silverback\ApiComponentsBundle\AttributeReader\UploadableAttributeReader;
@@ -69,10 +70,6 @@ public function createMediaObjects(object $object): ?ArrayCollection
6970
continue;
7071
}
7172

72-
if (!$filesystem->fileExists($path)) {
73-
continue;
74-
}
75-
7673
// todo: consultation on perhaps attributes which can be configured with environment variables or best way to achieve easier implementation
7774
$urlGeneratorReference = $fieldConfiguration->urlGenerator ?? 'api';
7875
$urlGenerator = $this->urlGenerators->get($urlGeneratorReference);
@@ -96,7 +93,7 @@ public function createMediaObjects(object $object): ?ArrayCollection
9693
try {
9794
$initialMediaObject = $this->create($filesystem, $path, $contentUrl);
9895
$propertyMediaObjects[] = $initialMediaObject;
99-
} catch (UnableToReadFile $exception) {
96+
} catch (UnableToReadFile|UnableToRetrieveMetadata) {
10097
continue;
10198
}
10299

0 commit comments

Comments
 (0)