Skip to content

Commit 5c4ee14

Browse files
Merge pull request #1198 from magento-frontend/MAGETWO-69515
Fixed issue: - MAGETWO-69515: Static files are deployed too slow for multiple locales
2 parents bd22a2c + 1e0f349 commit 5c4ee14

File tree

8 files changed

+83
-49
lines changed

8 files changed

+83
-49
lines changed

app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,34 @@ private function hasOverrides(PackageFile $parentFile, Package $package)
127127
$parentFile->getPackage()->getPath(),
128128
$parentFile->getExtension()
129129
);
130-
$parentFiles = $this->collectFileMap($parentFile->getFileName(), $map);
131-
$currentPackageLessFiles = $package->getFilesByType('less');
132-
$currentPackageCssFiles = $package->getFilesByType('css');
133130
/** @var PackageFile[] $currentPackageFiles */
134-
$currentPackageFiles = array_merge($currentPackageLessFiles, $currentPackageCssFiles);
131+
$currentPackageFiles = array_merge($package->getFilesByType('less'), $package->getFilesByType('css'));
135132

136133
foreach ($currentPackageFiles as $file) {
137-
if (in_array($file->getDeployedFileName(), $parentFiles)) {
134+
if ($this->inParentFiles($file->getDeployedFileName(), $parentFile->getFileName(), $map)) {
138135
return true;
139136
}
140137
}
138+
return false;
139+
}
141140

142-
$intersections = array_intersect($parentFiles, array_keys($currentPackageFiles));
143-
if ($intersections) {
144-
return true;
141+
/**
142+
* @param string $fileName
143+
* @param string $parentFile
144+
* @param array $map
145+
* @return bool
146+
*/
147+
private function inParentFiles($fileName, $parentFile, $map)
148+
{
149+
if (isset($map[$parentFile])) {
150+
if (in_array($fileName, $map[$parentFile])) {
151+
return true;
152+
} else {
153+
foreach ($map[$parentFile] as $pFile) {
154+
return $this->inParentFiles($fileName, $pFile, $map);
155+
}
156+
}
145157
}
146-
147158
return false;
148159
}
149160

@@ -186,25 +197,6 @@ private function buildMap($filePath, $packagePath, $contentType)
186197
return $this->map;
187198
}
188199

189-
/**
190-
* Flatten map tree into simple array
191-
*
192-
* Original map file information structure in form of tree,
193-
* and to have checking of overridden files simpler we need to flatten that tree
194-
*
195-
* @param string $fileName
196-
* @param array $map
197-
* @return array
198-
*/
199-
private function collectFileMap($fileName, array $map)
200-
{
201-
$result = isset($map[$fileName]) ? $map[$fileName] : [];
202-
foreach ($result as $fName) {
203-
$result = array_merge($result, $this->collectFileMap($fName, $map));
204-
}
205-
return array_unique($result);
206-
}
207-
208200
/**
209201
* Return normalized path
210202
*

app/code/Magento/Deploy/Process/Queue.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,15 @@ private function assertAndExecute($name, array & $packages, array $packageJob)
187187
{
188188
/** @var Package $package */
189189
$package = $packageJob['package'];
190-
$parentPackagesDeployed = true;
191190
if ($package->getParent() && $package->getParent() !== $package) {
192-
if (!$this->isDeployed($package->getParent())) {
193-
$parentPackagesDeployed = false;
194-
} else {
195-
$dependencies = $packageJob['dependencies'];
196-
foreach ($dependencies as $parentPackage) {
197-
if (!$this->isDeployed($parentPackage)) {
198-
$parentPackagesDeployed = false;
199-
break;
200-
}
191+
foreach ($packageJob['dependencies'] as $dependencyName => $dependency) {
192+
if (!$this->isDeployed($dependency)) {
193+
$this->assertAndExecute($dependencyName, $packages, $packages[$dependencyName]);
201194
}
202195
}
203196
}
204-
if (
205-
$parentPackagesDeployed
206-
&& ($this->maxProcesses < 2 || (count($this->inProgress) < $this->maxProcesses))
207-
) {
197+
if (!$this->isDeployed($package)
198+
&& ($this->maxProcesses < 2 || (count($this->inProgress) < $this->maxProcesses))) {
208199
unset($packages[$name]);
209200
$this->execute($package);
210201
}

app/code/Magento/Deploy/Service/DeployRequireJsConfig.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Deploy\Service;
77

8+
use Magento\Framework\Locale\ResolverInterfaceFactory;
9+
use Magento\Framework\Locale\ResolverInterface;
810
use Magento\RequireJs\Model\FileManagerFactory;
911
use Magento\Framework\View\DesignInterfaceFactory;
1012
use Magento\Framework\View\Design\Theme\ListInterface;
@@ -46,6 +48,11 @@ class DeployRequireJsConfig
4648
*/
4749
private $requireJsConfigFactory;
4850

51+
/**
52+
* @var ResolverInterfaceFactory
53+
*/
54+
private $localeFactory;
55+
4956
/**
5057
* DeployRequireJsConfig constructor
5158
*
@@ -54,31 +61,40 @@ class DeployRequireJsConfig
5461
* @param RepositoryFactory $assetRepoFactory
5562
* @param FileManagerFactory $fileManagerFactory
5663
* @param ConfigFactory $requireJsConfigFactory
64+
* @param ResolverInterfaceFactory $localeFactory
5765
*/
5866
public function __construct(
5967
ListInterface $themeList,
6068
DesignInterfaceFactory $designFactory,
6169
RepositoryFactory $assetRepoFactory,
6270
FileManagerFactory $fileManagerFactory,
63-
ConfigFactory $requireJsConfigFactory
71+
ConfigFactory $requireJsConfigFactory,
72+
ResolverInterfaceFactory $localeFactory
6473
) {
6574
$this->themeList = $themeList;
6675
$this->designFactory = $designFactory;
6776
$this->assetRepoFactory = $assetRepoFactory;
6877
$this->fileManagerFactory = $fileManagerFactory;
6978
$this->requireJsConfigFactory = $requireJsConfigFactory;
79+
$this->localeFactory = $localeFactory;
7080
}
7181

7282
/**
7383
* @param string $areaCode
7484
* @param string $themePath
85+
* @param string $localeCode
7586
* @return bool true on success
7687
*/
77-
public function deploy($areaCode, $themePath)
88+
public function deploy($areaCode, $themePath, $localeCode)
7889
{
7990
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
8091
$theme = $this->themeList->getThemeByFullPath($areaCode . '/' . $themePath);
92+
/** @var \Magento\Theme\Model\View\Design $design */
8193
$design = $this->designFactory->create()->setDesignTheme($theme, $areaCode);
94+
/** @var ResolverInterface $locale */
95+
$locale = $this->localeFactory->create();
96+
$locale->setLocale($localeCode);
97+
$design->setLocale($locale);
8298

8399
$assetRepo = $this->assetRepoFactory->create(['design' => $design]);
84100
/** @var \Magento\RequireJs\Model\FileManager $fileManager */

app/code/Magento/Deploy/Service/DeployStaticContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function deploy(array $options)
120120
]);
121121
foreach ($packages as $package) {
122122
if (!$package->isVirtual()) {
123-
$deployRjsConfig->deploy($package->getArea(), $package->getTheme());
123+
$deployRjsConfig->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
124124
$deployI18n->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
125125
$deployBundle->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
126126
}

app/code/Magento/Deploy/Test/Unit/Process/QueueTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ public function testAdd()
113113
public function testProcess()
114114
{
115115
$package = $this->getMock(Package::class, [], [], '', false);
116-
$package->expects($this->any())->method('getState')->willReturn(1);
117-
$package->expects($this->once())->method('getParent')->willReturn(null);
116+
$package->expects($this->any())->method('getState')->willReturn(0);
117+
$package->expects($this->exactly(2))->method('getParent')->willReturn(true);
118118
$package->expects($this->any())->method('getArea')->willReturn('area');
119119
$package->expects($this->any())->method('getPath')->willReturn('path');
120120
$package->expects($this->any())->method('getFiles')->willReturn([]);

app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function testDeploy($options, $expectedContentVersion)
123123
$package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
124124
$package->expects($this->exactly(3))->method('getArea')->willReturn('area');
125125
$package->expects($this->exactly(3))->method('getTheme')->willReturn('theme');
126-
$package->expects($this->exactly(2))->method('getLocale')->willReturn('locale');
126+
$package->expects($this->exactly(3))->method('getLocale')->willReturn('locale');
127127
}
128128
$packages = ['package' => $package];
129129

app/code/Magento/Theme/Model/View/Design.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ public function getLocale()
256256
return $this->_locale->getLocale();
257257
}
258258

259+
/**
260+
* @param \Magento\Framework\Locale\ResolverInterface $locale
261+
* @return $this
262+
*/
263+
public function setLocale(\Magento\Framework\Locale\ResolverInterface $locale)
264+
{
265+
$this->_locale = $locale;
266+
return $this;
267+
}
268+
259269
/**
260270
* {@inheritdoc}
261271
*/

dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DeployTest extends \PHPUnit_Framework_TestCase
8282
Options::EXCLUDE_AREA => ['none'],
8383
Options::THEME => ['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3'],
8484
Options::EXCLUDE_THEME => ['none'],
85-
Options::LANGUAGE => ['en_US'],
85+
Options::LANGUAGE => ['en_US', 'fr_FR', 'pl_PL'],
8686
Options::EXCLUDE_LANGUAGE => ['none'],
8787
Options::JOBS_AMOUNT => 0,
8888
Options::SYMLINK_LOCALE => false,
@@ -137,6 +137,12 @@ public function testDeploy()
137137
$this->assertFileExists($this->staticDir->getAbsolutePath('frontend/Magento/zoom3/default/css/root.css'));
138138
$this->assertFileExists($this->staticDir->getAbsolutePath('frontend/Magento/zoom3/default/css/local.css'));
139139

140+
$this->assertFileExistsIsGenerated('requirejs-config.js');
141+
$this->assertFileExistsIsGenerated('requirejs-map.js');
142+
$this->assertFileExistsIsGenerated('map.json');
143+
$this->assertFileExistsIsGenerated('js-translation.json');
144+
$this->assertFileExistsIsGenerated('result_map.json');
145+
140146
$actualFileContent = $this->staticDir->readFile('frontend/Magento/zoom3/default/css/root.css');
141147
$this->assertLessPreProcessor($actualFileContent);
142148
$this->assertCssUrlFixerPostProcessor($actualFileContent);
@@ -148,6 +154,25 @@ public function testDeploy()
148154
}
149155
}
150156

157+
/**
158+
* Assert file exists in all themes and locales
159+
*
160+
* @param string $fileName
161+
* @return void
162+
*/
163+
private function assertFileExistsIsGenerated($fileName)
164+
{
165+
foreach (['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3'] as $theme) {
166+
foreach ($this->options[Options::LANGUAGE] as $locale) {
167+
$this->assertFileExists(
168+
$this->staticDir->getAbsolutePath(
169+
'frontend/' . $theme . '/' . $locale . '/' . $fileName
170+
)
171+
);
172+
}
173+
}
174+
}
175+
151176
/**
152177
* Assert Less pre-processor
153178
*

0 commit comments

Comments
 (0)