Skip to content

Commit 5e6e0ef

Browse files
bl4deeliseacornejo
andauthored
LYNX-193: Cache for empty AttributesList query result (#130)
* 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 <[email protected]>
1 parent e169198 commit 5e6e0ef

File tree

3 files changed

+22
-42
lines changed

3 files changed

+22
-42
lines changed

app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function resolve(
7777

7878
return [
7979
'items' => $this->getAttributesMetadata($attributesList['items'], $entityType, $storeId),
80+
'entity_type' => $entityType,
8081
'errors' => $attributesList['errors']
8182
];
8283
}

app/code/Magento/EavGraphQl/Model/Resolver/Cache/AttributesListIdentity.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ class AttributesListIdentity implements IdentityInterface
2222
*/
2323
public function getIdentities(array $resolvedData): array
2424
{
25-
if (empty($resolvedData['items']) || !is_array($resolvedData['items'][0])) {
25+
if (empty($resolvedData['entity_type']) || $resolvedData['entity_type'] === "") {
2626
return [];
2727
}
2828

29-
$item = $resolvedData['items'][0];
30-
$identities = [];
29+
$identities = [
30+
Config::ENTITIES_CACHE_ID . "_" . $resolvedData['entity_type'] . "_ENTITY"
31+
];
3132

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

3637
foreach ($resolvedData['items'] as $item) {

dev/tests/api-functional/testsuite/Magento/GraphQl/EavGraphQl/AttributesListCacheTest.php

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,10 @@ public function testAttributeListCacheInvalidateOnAttributeDelete()
246246
}
247247
}
248248

249-
if (empty($response['body']['attributesList']['items'])) {
250-
$this->assertCacheMissAndReturnResponse(
251-
self::QUERY,
252-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
253-
);
254-
} else {
255-
$this->assertCacheHitAndReturnResponse(
256-
self::QUERY,
257-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
258-
);
259-
}
249+
$this->assertCacheHitAndReturnResponse(
250+
self::QUERY,
251+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
252+
);
260253
}
261254

262255
#[
@@ -288,22 +281,14 @@ public function testAttributeListCacheInvalidateOnAttributeEdit()
288281
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
289282
);
290283

291-
$response = $this->assertCacheMissAndReturnResponse(
284+
$this->assertCacheMissAndReturnResponse(
292285
self::QUERY_ADDRESS,
293286
[CacheIdCalculator::CACHE_ID_HEADER => $cacheAddressId]
294287
);
295-
296-
if (empty($response['body']['attributesList']['items'])) {
297-
$this->assertCacheMissAndReturnResponse(
298-
self::QUERY_ADDRESS,
299-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
300-
);
301-
} else {
302-
$this->assertCacheHitAndReturnResponse(
303-
self::QUERY_ADDRESS,
304-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
305-
);
306-
}
288+
$this->assertCacheHitAndReturnResponse(
289+
self::QUERY_ADDRESS,
290+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
291+
);
307292

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

320-
$this->assertCacheMissAndReturnResponse(
305+
$this->assertCacheHitAndReturnResponse(
321306
self::QUERY_ADDRESS,
322307
[CacheIdCalculator::CACHE_ID_HEADER => $cacheAddressId]
323308
);
@@ -403,22 +388,15 @@ public function testAttributesListCacheMissAndHitNewAttribute()
403388
{
404389
$cacheId = $this->getCacheIdHeader(self::QUERY);
405390

406-
$response = $this->assertCacheMissAndReturnResponse(
391+
$this->assertCacheMissAndReturnResponse(
407392
self::QUERY,
408393
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
409394
);
410395

411-
if (empty($response['body']['attributesList']['items'])) {
412-
$this->assertCacheMissAndReturnResponse(
413-
self::QUERY,
414-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
415-
);
416-
} else {
417-
$this->assertCacheHitAndReturnResponse(
418-
self::QUERY,
419-
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
420-
);
421-
}
396+
$this->assertCacheHitAndReturnResponse(
397+
self::QUERY,
398+
[CacheIdCalculator::CACHE_ID_HEADER => $cacheId]
399+
);
422400

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

0 commit comments

Comments
 (0)