Skip to content

Commit

Permalink
optimize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mardl committed Feb 13, 2024
1 parent 0b03ff0 commit 866f0ed
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Repositories/ImageTypeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,34 @@ public function init()
public function findAll()
{
// query whether we've already loaded the value
if (!isset($this->cache[__METHOD__])) {
// initialize the result array
$result = [];

// load and the image types from the EAV attribute table
$this->imageTypesByEntityTypeCodeAndFrontendInputStmt->execute();
if (isset($this->cache[__METHOD__])) {
return $this->cache[__METHOD__];
}
// initialize the result array
$result = [];

// fetch the image types with the passed parameters
if ($imageTypes = $this->imageTypesByEntityTypeCodeAndFrontendInputStmt->fetchAll(\PDO::FETCH_ASSOC)) {
// iterate over the image types found
foreach ($imageTypes as $imageType) {
$attributeCode = $imageType[MemberNames::ATTRIBUTE_CODE];
// map the default image types
if (isset($this->defaultMappings[$attributeCode])) {
$attributeCode = $this->defaultMappings[$attributeCode];
}
// load and the image types from the EAV attribute table
$this->imageTypesByEntityTypeCodeAndFrontendInputStmt->execute();

// add the (mapped) image type
$result[$attributeCode] = sprintf('%s_label', $attributeCode);
// fetch the image types with the passed parameters
if ($imageTypes = $this->imageTypesByEntityTypeCodeAndFrontendInputStmt->fetchAll(\PDO::FETCH_ASSOC)) {
// iterate over the image types found
foreach ($imageTypes as $imageType) {
$attributeCode = $imageType[MemberNames::ATTRIBUTE_CODE];
// map the default image types
if (isset($this->defaultMappings[$attributeCode])) {
$attributeCode = $this->defaultMappings[$attributeCode];
}
}

// append to the cache
$this->cache[__METHOD__] = $result;
// add the (mapped) image type
$result[$attributeCode] = sprintf('%s_label', $attributeCode);
}
}

// append to the cache
$this->cache[__METHOD__] = $result;

// return from the cache
return $this->cache[__METHOD__];
}
Expand Down

0 comments on commit 866f0ed

Please sign in to comment.