Skip to content

Commit

Permalink
LYNX-193: Cache for empty AttributesList query result (#130)
Browse files Browse the repository at this point in the history
* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query
- Review comment and static checkss

* LYNX-183: Add filters to attributesList query

* LYNX-183: Fix for EAV attributes cache invalidation

* LYNX-183: Fix for EAV attributes cache invalidation

* LYNX-183: Fix for EAV attributes cache invalidation

* LYNX-183: Fix for EAV attributes cache invalidation

* LYNX-183: Fix for AttributesList query cache when result set is empty

* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query
- check what is failing in github

* LYNX-183: Add filters to attributesList query
- Remove print

* LYNX-183: Add filters to attributesList query

* LYNX-183: Add filters to attributesList query3

* LYNX-183: Add filters to attributesList query

* LYNX-193: Cache for empty AttributesList query result

* LYNX-193: Fix static tests

---------

Co-authored-by: Elisea Cornejo <ecornejo@adobe.com>
  • Loading branch information
bl4de and eliseacornejo authored Jul 17, 2023
1 parent e169198 commit 5e6e0ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function resolve(

return [
'items' => $this->getAttributesMetadata($attributesList['items'], $entityType, $storeId),
'entity_type' => $entityType,
'errors' => $attributesList['errors']
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ class AttributesListIdentity implements IdentityInterface
*/
public function getIdentities(array $resolvedData): array
{
if (empty($resolvedData['items']) || !is_array($resolvedData['items'][0])) {
if (empty($resolvedData['entity_type']) || $resolvedData['entity_type'] === "") {
return [];
}

$item = $resolvedData['items'][0];
$identities = [];
$identities = [
Config::ENTITIES_CACHE_ID . "_" . $resolvedData['entity_type'] . "_ENTITY"
];

if ($item['entity_type'] !== '') {
$identities[] = Config::ENTITIES_CACHE_ID . "_" . $item['entity_type'] . "_ENTITY";
if (empty($resolvedData['items']) || !is_array($resolvedData['items'][0])) {
return $identities;
}

foreach ($resolvedData['items'] as $item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,10 @@ public function testAttributeListCacheInvalidateOnAttributeDelete()
}
}

if (empty($response['body']['attributesList']['items'])) {
$this->assertCacheMissAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
} else {
$this->assertCacheHitAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
}
$this->assertCacheHitAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
}

#[
Expand Down Expand Up @@ -288,22 +281,14 @@ public function testAttributeListCacheInvalidateOnAttributeEdit()
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);

$response = $this->assertCacheMissAndReturnResponse(
$this->assertCacheMissAndReturnResponse(
self::QUERY_ADDRESS,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheAddressId]
);

if (empty($response['body']['attributesList']['items'])) {
$this->assertCacheMissAndReturnResponse(
self::QUERY_ADDRESS,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
} else {
$this->assertCacheHitAndReturnResponse(
self::QUERY_ADDRESS,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
}
$this->assertCacheHitAndReturnResponse(
self::QUERY_ADDRESS,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);

$customerAttribute0->setDefaultValue('after change default value');
$this->eavAttributeRepo->save($customerAttribute0);
Expand All @@ -317,7 +302,7 @@ public function testAttributeListCacheInvalidateOnAttributeEdit()
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);

$this->assertCacheMissAndReturnResponse(
$this->assertCacheHitAndReturnResponse(
self::QUERY_ADDRESS,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheAddressId]
);
Expand Down Expand Up @@ -403,22 +388,15 @@ public function testAttributesListCacheMissAndHitNewAttribute()
{
$cacheId = $this->getCacheIdHeader(self::QUERY);

$response = $this->assertCacheMissAndReturnResponse(
$this->assertCacheMissAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);

if (empty($response['body']['attributesList']['items'])) {
$this->assertCacheMissAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
} else {
$this->assertCacheHitAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);
}
$this->assertCacheHitAndReturnResponse(
self::QUERY,
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
);

$newAttributeCreate = Bootstrap::getObjectManager()->get(CustomerAttribute::class);
/** @var AttributeInterface $newAttribute */
Expand Down

0 comments on commit 5e6e0ef

Please sign in to comment.