Skip to content

Commit 35e3225

Browse files
committed
Only resize images for themes which are being used instead of all installed themes.
1 parent 18a58db commit 35e3225

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

app/code/Magento/Catalog/Model/Product/Image/Cache.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Helper\Image as ImageHelper;
99
use Magento\Catalog\Model\Product;
1010
use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection;
11+
use Magento\Theme\Model\Config\Customization as ThemeCustomizationConfig;
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\View\ConfigInterface;
1314

@@ -23,6 +24,11 @@ class Cache
2324
*/
2425
protected $themeCollection;
2526

27+
/**
28+
* @var ThemeCustomizationConfig
29+
*/
30+
protected $themeCustomizationConfig;
31+
2632
/**
2733
* @var ImageHelper
2834
*/
@@ -41,10 +47,12 @@ class Cache
4147
public function __construct(
4248
ConfigInterface $viewConfig,
4349
ThemeCollection $themeCollection,
44-
ImageHelper $imageHelper
50+
ImageHelper $imageHelper,
51+
ThemeCustomizationConfig $themeCustomizationConfig
4552
) {
4653
$this->viewConfig = $viewConfig;
4754
$this->themeCollection = $themeCollection;
55+
$this->themeCustomizationConfig = $themeCustomizationConfig;
4856
$this->imageHelper = $imageHelper;
4957
}
5058

@@ -58,8 +66,10 @@ public function __construct(
5866
protected function getData()
5967
{
6068
if (!$this->data) {
69+
$themes = $this->getThemesInUse();
70+
6171
/** @var \Magento\Theme\Model\Theme $theme */
62-
foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
72+
foreach ($themes as $theme) {
6373
$config = $this->viewConfig->getViewConfig([
6474
'area' => Area::AREA_FRONTEND,
6575
'themeModel' => $theme,
@@ -127,4 +137,20 @@ protected function processImageData(Product $product, array $imageData, $file)
127137

128138
return $this;
129139
}
140+
141+
protected function getThemesInUse()
142+
{
143+
$themesInUse = [];
144+
145+
$registeredThemes = $this->themeCollection->loadRegisteredThemes();
146+
$storesByThemes = $this->themeCustomizationConfig->getStoresByThemes();
147+
148+
foreach ($registeredThemes as $registeredTheme) {
149+
if (array_key_exists($registeredTheme->getThemeId(), $storesByThemes)) {
150+
$themesInUse[] = $registeredTheme;
151+
}
152+
}
153+
154+
return $themesInUse;
155+
}
130156
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Image/CacheTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class CacheTest extends \PHPUnit_Framework_TestCase
4343
*/
4444
protected $themeCollection;
4545

46+
/**
47+
* @var \Magento\Theme\Model\Config\Customization|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
protected $themeCustomizationConfig;
50+
4651
/**
4752
* @var \Magento\Catalog\Helper\Image|\PHPUnit_Framework_MockObject_MockObject
4853
*/
@@ -70,6 +75,10 @@ protected function setUp()
7075
->disableOriginalConstructor()
7176
->getMock();
7277

78+
$this->themeCustomizationConfig = $this->getMockBuilder(\Magento\Theme\Model\Config\Customization::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
7382
$this->imageHelper = $this->getMockBuilder(\Magento\Catalog\Helper\Image::class)
7483
->disableOriginalConstructor()
7584
->getMock();
@@ -84,6 +93,7 @@ protected function setUp()
8493
[
8594
'viewConfig' => $this->viewConfig,
8695
'themeCollection' => $this->themeCollection,
96+
'themeCustomizationConfig' => $this->themeCustomizationConfig,
8797
'imageHelper' => $this->imageHelper,
8898
]
8999
);
@@ -126,6 +136,12 @@ public function testGenerate()
126136
->method('loadRegisteredThemes')
127137
->willReturn([$themeMock]);
128138

139+
$this->themeCustomizationConfig->expects($this->once())
140+
->method('getStoresByThemes')
141+
->willReturn([
142+
$themeMock->getThemeId() => [1]
143+
]);
144+
129145
$this->viewConfig->expects($this->once())
130146
->method('getViewConfig')
131147
->with([

0 commit comments

Comments
 (0)