Skip to content

Commit a52725d

Browse files
committed
MAGETWO-95215: [GraphQL] Performance issue in filters realization
- Fixed code style violations
1 parent dab0c0e commit a52725d

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

app/code/Magento/Catalog/Model/Product/Media/Config.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
use Magento\Store\Model\StoreManagerInterface;
1111

1212
/**
13-
* Catalog product media config
13+
* Catalog product media config.
1414
*
1515
* @api
16-
*
17-
* @author Magento Core Team <core@magentocommerce.com>
1816
* @since 100.0.2
1917
*/
2018
class Config implements ConfigInterface
@@ -45,8 +43,7 @@ public function __construct(StoreManagerInterface $storeManager)
4543
}
4644

4745
/**
48-
* Filesystem directory path of product images
49-
* relatively to media folder
46+
* Get filesystem directory path for product images relative to the media directory.
5047
*
5148
* @return string
5249
*/
@@ -56,8 +53,7 @@ public function getBaseMediaPathAddition()
5653
}
5754

5855
/**
59-
* Web-based directory path of product images
60-
* relatively to media folder
56+
* Get web-based directory path for product images relative to the media directory.
6157
*
6258
* @return string
6359
*/
@@ -67,15 +63,15 @@ public function getBaseMediaUrlAddition()
6763
}
6864

6965
/**
70-
* @return string
66+
* @inheritdoc
7167
*/
7268
public function getBaseMediaPath()
7369
{
7470
return 'catalog/product';
7571
}
7672

7773
/**
78-
* @return string
74+
* @inheritdoc
7975
*/
8076
public function getBaseMediaUrl()
8177
{
@@ -84,8 +80,7 @@ public function getBaseMediaUrl()
8480
}
8581

8682
/**
87-
* Filesystem directory path of temporary product images
88-
* relatively to media folder
83+
* Filesystem directory path of temporary product images relative to the media directory.
8984
*
9085
* @return string
9186
*/
@@ -95,6 +90,8 @@ public function getBaseTmpMediaPath()
9590
}
9691

9792
/**
93+
* Get temporary base media URL.
94+
*
9895
* @return string
9996
*/
10097
public function getBaseTmpMediaUrl()
@@ -105,24 +102,24 @@ public function getBaseTmpMediaUrl()
105102
}
106103

107104
/**
108-
* @param string $file
109-
* @return string
105+
* @inheritdoc
110106
*/
111107
public function getMediaUrl($file)
112108
{
113109
return $this->getBaseMediaUrl() . '/' . $this->_prepareFile($file);
114110
}
115111

116112
/**
117-
* @param string $file
118-
* @return string
113+
* @inheritdoc
119114
*/
120115
public function getMediaPath($file)
121116
{
122117
return $this->getBaseMediaPath() . '/' . $this->_prepareFile($file);
123118
}
124119

125120
/**
121+
* Get temporary media URL.
122+
*
126123
* @param string $file
127124
* @return string
128125
*/
@@ -132,8 +129,7 @@ public function getTmpMediaUrl($file)
132129
}
133130

134131
/**
135-
* Part of URL of temporary product images
136-
* relatively to media folder
132+
* Part of URL of temporary product images relative to the media directory.
137133
*
138134
* @param string $file
139135
* @return string
@@ -144,7 +140,7 @@ public function getTmpMediaShortUrl($file)
144140
}
145141

146142
/**
147-
* Part of URL of product images relatively to media folder
143+
* Part of URL of product images relatively to media folder.
148144
*
149145
* @param string $file
150146
* @return string
@@ -155,6 +151,8 @@ public function getMediaShortUrl($file)
155151
}
156152

157153
/**
154+
* Get path to the temporary media.
155+
*
158156
* @param string $file
159157
* @return string
160158
*/
@@ -164,6 +162,8 @@ public function getTmpMediaPath($file)
164162
}
165163

166164
/**
165+
* Process file path.
166+
*
167167
* @param string $file
168168
* @return string
169169
*/
@@ -173,18 +173,23 @@ protected function _prepareFile($file)
173173
}
174174

175175
/**
176+
* Get codes of media attribute.
177+
*
176178
* @return array
177179
* @since 100.0.4
178180
*/
179181
public function getMediaAttributeCodes()
180182
{
181183
if (!isset($this->mediaAttributeCodes)) {
184+
// the in-memory object-level caching allows to prevent unnecessary calls to the DB
182185
$this->mediaAttributeCodes = $this->getAttributeHelper()->getAttributeCodesByFrontendType('media_image');
183186
}
184187
return $this->mediaAttributeCodes;
185188
}
186189

187190
/**
191+
* Get attribute helper.
192+
*
188193
* @return Attribute
189194
*/
190195
private function getAttributeHelper()

app/code/Magento/CatalogGraphQl/Model/Resolver/Categories.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function __construct(
7878
}
7979

8080
/**
81-
* {@inheritdoc}
81+
* @inheritdoc
82+
*
8283
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8384
*/
8485
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
@@ -106,7 +107,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
106107
/** @var CategoryInterface | \Magento\Catalog\Model\Category $item */
107108
foreach ($this->collection as $item) {
108109
if (in_array($item->getId(), $categoryIds)) {
109-
110110
// Try to extract all requested fields from the loaded collection data
111111
$categories[$item->getId()] = $this->categoryHydrator->hydrateCategory($item, true);
112112
$requestedFields = $that->attributesJoiner->getQueryFields($info->fieldNodes[0]);
@@ -118,7 +118,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
118118

119119
// If not all requested fields were extracted from the collection, start more complex extraction
120120
$categories[$item->getId()] = $this->categoryHydrator->hydrateCategory($item);
121-
122121
}
123122
}
124123

lib/internal/Magento/Framework/GraphQl/Config.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct(
5353
* @param string $configElementName
5454
* @return ConfigElementInterface
5555
* @throws \LogicException
56+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
5657
*/
5758
public function getConfigElement(string $configElementName) : ConfigElementInterface
5859
{
@@ -65,11 +66,11 @@ public function getConfigElement(string $configElementName) : ConfigElementInter
6566

6667
$fieldsInQuery = $this->queryFields->getFieldsUsedInQuery();
6768
if (isset($data['fields']) && !empty($fieldsInQuery)) {
68-
foreach ($data['fields'] as $fieldName => $fieldConfig) {
69-
if (!isset($fieldsInQuery[$fieldName])) {
70-
unset($data['fields'][$fieldName]);
71-
}
72-
}
69+
foreach ($data['fields'] as $fieldName => $fieldConfig) {
70+
if (!isset($fieldsInQuery[$fieldName])) {
71+
unset($data['fields'][$fieldName]);
72+
}
73+
}
7374
}
7475

7576
return $this->configElementFactory->createFromConfigData($data);

0 commit comments

Comments
 (0)