Skip to content

Commit 048569a

Browse files
author
Oleksii Korshenko
authored
Merge pull request #477 from magento-performance/MAGETWO-58320
Fixed issues: - MAGETWO-58320: Eliminate Slow Query for Media Gallery data - MAGETWO-59398: [Cloud] Custom theme does not use parent xml configuration on multi thread deployment - MAGETWO-59310: Static Assets deployment throws errors when redis is used for cache
2 parents 6132d84 + 3ef890a commit 048569a

File tree

6 files changed

+156
-10
lines changed

6 files changed

+156
-10
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@ public function addPriceDataFieldFilter($comparisonFormat, $fields)
21712171
*/
21722172
public function addMediaGalleryData()
21732173
{
2174+
21742175
if ($this->getFlag('media_gallery_added')) {
21752176
return $this;
21762177
}
@@ -2186,7 +2187,11 @@ public function addMediaGalleryData()
21862187
$this->getStoreId(),
21872188
$attribute->getAttributeId()
21882189
);
2189-
2190+
2191+
$select->where('entity.entity_id IN (?)', array_map(function ($item) {
2192+
return $item->getId();
2193+
}, $this->getItems()));
2194+
21902195
foreach ($this->getConnection()->fetchAll($select) as $row) {
21912196
$mediaGalleries[$row['entity_id']][] = $row;
21922197
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected $collection;
3030

31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $galleryResourceMock;
35+
36+
/**
37+
* @var \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $entityMock;
40+
3141
/**
3242
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
3343
*/
@@ -98,18 +108,22 @@ public function setUp()
98108
->disableOriginalConstructor()
99109
->getMock();
100110

101-
$entityMock = $this->getMockBuilder('Magento\Eav\Model\Entity\AbstractEntity')
111+
$this->entityMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
102112
->disableOriginalConstructor()
103113
->getMock();
104114

115+
$this->galleryResourceMock = $this->getMockBuilder(
116+
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media::class
117+
)->disableOriginalConstructor()->getMock();
118+
105119
$storeManager->expects($this->any())->method('getId')->willReturn(1);
106120
$storeManager->expects($this->any())->method('getStore')->willReturnSelf();
107121
$universalFactory->expects($this->exactly(1))->method('create')->willReturnOnConsecutiveCalls(
108-
$entityMock
122+
$this->entityMock
109123
);
110-
$entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
111-
$entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([]);
112-
$entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
124+
$this->entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
125+
$this->entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([]);
126+
$this->entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
113127
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);
114128
$helper = new ObjectManager($this);
115129
$this->collection = $helper->getObject(
@@ -138,6 +152,11 @@ public function setUp()
138152
]
139153
);
140154
$this->collection->setConnection($this->connectionMock);
155+
156+
$reflection = new \ReflectionClass(get_class($this->collection));
157+
$reflectionProperty = $reflection->getProperty('mediaGalleryResource');
158+
$reflectionProperty->setAccessible(true);
159+
$reflectionProperty->setValue($this->collection, $this->galleryResourceMock);
141160
}
142161

143162
public function testAddProductCategoriesFilter()
@@ -165,4 +184,42 @@ public function testAddProductCategoriesFilter()
165184
)->willReturnSelf();
166185
$this->collection->addCategoriesFilter([$conditionType => $values]);
167186
}
187+
188+
public function testAddMediaGalleryData()
189+
{
190+
$attributeId = 42;
191+
$itemId = 4242;
192+
$mediaGalleriesMock = [['entity_id' => $itemId]];
193+
$itemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
194+
->disableOriginalConstructor()
195+
->getMock();
196+
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
197+
->disableOriginalConstructor()
198+
->getMock();
199+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
200+
->disableOriginalConstructor()
201+
->getMock();
202+
$backendMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Attribute\Backend\Media::class)
203+
->disableOriginalConstructor()
204+
->getMock();
205+
$this->collection->addItem($itemMock);
206+
$reflection = new \ReflectionClass(get_class($this->collection));
207+
$reflectionProperty = $reflection->getProperty('_isCollectionLoaded');
208+
$reflectionProperty->setAccessible(true);
209+
$reflectionProperty->setValue($this->collection, true);
210+
211+
$this->galleryResourceMock->expects($this->once())->method('createBatchBaseSelect')->willReturn($selectMock);
212+
$attributeMock->expects($this->once())->method('getAttributeId')->willReturn($attributeId);
213+
$this->entityMock->expects($this->once())->method('getAttribute')->willReturn($attributeMock);
214+
$itemMock->expects($this->atLeastOnce())->method('getId')->willReturn($itemId);
215+
$selectMock->expects($this->once())->method('where')->with('entity.entity_id IN (?)', [$itemId]);
216+
217+
$this->connectionMock->expects($this->once())->method('fetchAll')->with($selectMock)->willReturn(
218+
[['entity_id' => $itemId]]
219+
);
220+
$attributeMock->expects($this->once())->method('getBackend')->willReturn($backendMock);
221+
$backendMock->expects($this->once())->method('addMediaDataToProduct')->with($itemMock, $mediaGalleriesMock);
222+
223+
$this->assertSame($this->collection, $this->collection->addMediaGalleryData());
224+
}
168225
}

app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\Validator\Locale;
1818
use Magento\Deploy\Console\Command\DeployStaticOptionsInterface as Options;
1919
use Magento\Deploy\Model\DeployManager;
20+
use Magento\Framework\App\Cache;
21+
use Magento\Framework\App\Cache\Type\Dummy as DummyCache;
2022

2123
/**
2224
* Deploy static content command
@@ -380,6 +382,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
380382
}
381383
}
382384

385+
$this->mockCache();
383386
return $deployManager->deploy();
384387
}
385388

@@ -441,4 +444,18 @@ private function prepareDeployableEntities($filesUtil)
441444

442445
return [$deployableLanguages, $deployableAreaThemeMap, $requestedThemes];
443446
}
447+
448+
/**
449+
* Mock Cache class with dummy implementation
450+
*
451+
* @return void
452+
*/
453+
private function mockCache()
454+
{
455+
$this->objectManager->configure([
456+
'preferences' => [
457+
Cache::class => DummyCache::class
458+
]
459+
]);
460+
}
444461
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\App\Cache\Type;
7+
8+
use Magento\Framework\App\CacheInterface;
9+
10+
/**
11+
* Dummy cache adapter
12+
*
13+
* for cases when need to disable interaction with cache
14+
* but no specific cache type is used
15+
*/
16+
class Dummy implements CacheInterface
17+
{
18+
/**
19+
* Required by CacheInterface
20+
*
21+
* @return null
22+
*/
23+
public function getFrontend()
24+
{
25+
return null;
26+
}
27+
28+
/**
29+
* Pretend to load data from cache by id
30+
*
31+
* {@inheritdoc}
32+
*/
33+
public function load($identifier)
34+
{
35+
return null;
36+
}
37+
38+
/**
39+
* Pretend to save data
40+
*
41+
* {@inheritdoc}
42+
*/
43+
public function save($data, $identifier, $tags = [], $lifeTime = null)
44+
{
45+
return false;
46+
}
47+
48+
/**
49+
* Pretend to remove cached data by identifier
50+
*
51+
* {@inheritdoc}
52+
*/
53+
public function remove($identifier)
54+
{
55+
return true;
56+
}
57+
58+
/**
59+
* Pretend to clean cached data by specific tag
60+
*
61+
* {@inheritdoc}
62+
*/
63+
public function clean($tags = [])
64+
{
65+
return true;
66+
}
67+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getViewConfig(array $params = [])
6262
if (isset($params['themeModel'])) {
6363
/** @var \Magento\Framework\View\Design\ThemeInterface $currentTheme */
6464
$currentTheme = $params['themeModel'];
65-
$key = $currentTheme->getCode();
65+
$key = $currentTheme->getFullPath();
6666
if (isset($this->viewConfigs[$key])) {
6767
return $this->viewConfigs[$key];
6868
}

lib/internal/Magento/Framework/View/Test/Unit/ConfigTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ protected function setUp()
4040

4141
public function testGetViewConfig()
4242
{
43-
$themeCode = 2;
43+
$themeCode = 'area/theme';
4444

4545
$themeMock = $this->getMock(
4646
\Magento\Theme\Model\Theme::class,
47-
['getCode'],
47+
['getFullPath'],
4848
[],
4949
'',
5050
false
5151
);
5252
$themeMock->expects($this->atLeastOnce())
53-
->method('getCode')
53+
->method('getFullPath')
5454
->will($this->returnValue($themeCode));
5555
$params = [
5656
'themeModel' => $themeMock,

0 commit comments

Comments
 (0)