Skip to content

Commit 73ab3f0

Browse files
committed
MCP-811: Performance Optimization for Catalog GraphQL
- Update unit test;
1 parent 9250ce4 commit 73ab3f0

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function getEntityStorage(array $queryResult)
5959
{
6060
$ids = [];
6161
foreach ($queryResult['hits']['hits'] as $document) {
62-
if (!array_key_exists('_id', $document) && array_key_exists('_id', $document['fields'])) {
62+
if (!array_key_exists('_id', $document) && isset($document['fields']['_id'][0])) {
6363
$document['_id'] = $document['fields']['_id'][0];
6464
unset($document['fields']);
6565
}

app/code/Magento/Elasticsearch/SearchAdapter/ResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function create($response)
6464
{
6565
$documents = [];
6666
foreach ($response['documents'] as $rawDocument) {
67-
if (!array_key_exists('_id', $rawDocument) && array_key_exists('_id', $rawDocument['fields'])) {
67+
if (!array_key_exists('_id', $rawDocument) && isset($rawDocument['fields']['_id'][0])) {
6868
$rawDocument['_id'] = $rawDocument['fields']['_id'][0];
6969
unset($rawDocument['fields']);
7070
}

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/ResponseFactoryTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,32 @@ protected function setUp(): void
7272
public function testCreate(): void
7373
{
7474
$documents = [
75-
['title' => 'oneTitle', 'description' => 'oneDescription'],
76-
['title' => 'twoTitle', 'description' => 'twoDescription']
75+
[
76+
'title' => 'oneTitle',
77+
'description' => 'oneDescription',
78+
'fields' => [
79+
'_id' => ['1']
80+
]
81+
],
82+
[
83+
'title' => 'twoTitle',
84+
'description' => 'twoDescription',
85+
'fields' => [
86+
'_id' => ['2']
87+
]
88+
]
89+
];
90+
$modifiedDocuments = [
91+
[
92+
'title' => 'oneTitle',
93+
'description' => 'oneDescription',
94+
'_id' => '1'
95+
],
96+
[
97+
'title' => 'twoTitle',
98+
'description' => 'twoDescription',
99+
'_id' => '2'
100+
]
77101
];
78102
$aggregations = [
79103
'aggregation1' => [
@@ -113,7 +137,7 @@ public function testCreate(): void
113137

114138
$this->documentFactory
115139
->method('create')
116-
->withConsecutive([$documents[0]], [$documents[1]])
140+
->withConsecutive([$modifiedDocuments[0]], [$modifiedDocuments[1]])
117141
->willReturnOnConsecutiveCalls('document1', 'document2');
118142

119143
$this->aggregationFactory

0 commit comments

Comments
 (0)