Skip to content

Commit

Permalink
LYNX-149: Cache identity for attributesMetadata query (#114)
Browse files Browse the repository at this point in the history
* LYNX-149: Cache identity for attributesMetadata query
  • Loading branch information
eliseacornejo authored May 16, 2023
1 parent 29519af commit 6c4024f
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function execute(
int $storeId
): array {
return [
'id' => $attribute->getAttributeId(),
'uid' => $this->attributeUid->encode($entityType, $attribute->getAttributeCode()),
'code' => $attribute->getAttributeCode(),
'label' => $attribute->getStoreLabel($storeId),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\EavGraphQl\Model\Resolver\Cache;

use Magento\Eav\Model\Entity\Attribute as EavAttribute;
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;

/**
* Cache identity provider for custom attribute metadata query results.
*/
class CustomAttributeMetadataV2Identity implements IdentityInterface
{
/**
* @inheritDoc
*/
public function getIdentities(array $resolvedData): array
{
$identities = [];
if (isset($resolvedData['items']) && !empty($resolvedData['items'])) {
foreach ($resolvedData['items'] as $item) {
if (is_array($item)) {
$identities[] = sprintf(
"%s_%s",
EavAttribute::CACHE_TAG,
$item['id']
);
}
}
} else {
return [];
}
return $identities;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/EavGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Query {
@doc(description: "Return the attribute type, given an attribute code and entity type.")
@cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataIdentity")
@deprecated(reason: "Use `customAttributeMetadataV2` query instead.")
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.")
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.") @cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataV2Identity")
attributesForm(formCode: String! @doc(description: "Form code.")): AttributesFormOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesForm") @doc(description: "Retrieve EAV attributes associated to a frontend form.")
attributesList(entityType: AttributeEntityTypeEnum! @doc(description: "Entity type.")): AttributesMetadataOutput @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesList") @doc(description: "Returns a list of attributes metadata for a given entity type.") @cache(cacheable: false)
}
Expand Down
Loading

0 comments on commit 6c4024f

Please sign in to comment.