Skip to content

Commit 12feeff

Browse files
ENGCOM-8419: Speedup static content deploy for specific theme #30090
2 parents 27a3a19 + f638d19 commit 12feeff

File tree

5 files changed

+184
-72
lines changed

5 files changed

+184
-72
lines changed

app/code/Magento/Deploy/Console/DeployStaticOptions.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace Magento\Deploy\Console;
88

99
use Magento\Deploy\Process\Queue;
10-
use Symfony\Component\Console\Input\InputOption;
1110
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputOption;
1212

1313
/**
1414
* Static Content Deployment Options helper
@@ -127,6 +127,11 @@ class DeployStaticOptions
127127
*/
128128
const NO_LESS = 'no-less';
129129

130+
/**
131+
* Key for not compiling parent themes
132+
*/
133+
const NO_PARENT = 'no-parent';
134+
130135
const DEFAULT_JOBS_AMOUNT = 0;
131136

132137
/**
@@ -324,7 +329,13 @@ private function getSkipOptions()
324329
null,
325330
InputOption::VALUE_NONE,
326331
'Do not minify HTML files.'
327-
)
332+
),
333+
new InputOption(
334+
self::NO_PARENT,
335+
null,
336+
InputOption::VALUE_NONE,
337+
'Do not compile parent themes. Supported only in quick and standard strategies.'
338+
),
328339
];
329340
}
330341
}

app/code/Magento/Deploy/Console/InputValidator.php

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Deploy\Console;
78

8-
use Magento\Setup\Console\Command\DeployStaticContentCommand;
9+
use InvalidArgumentException;
910
use Magento\Deploy\Console\DeployStaticOptions as Options;
10-
use Magento\Framework\Validator\Locale;
11-
use Symfony\Component\Console\Input\InputInterface;
1211
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Validator\Locale;
1313
use Magento\Framework\Validator\RegexFactory;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use function array_key_exists;
1416

1517
/**
1618
* Command input arguments validator class
@@ -66,7 +68,7 @@ class InputValidator
6668
* InputValidator constructor
6769
*
6870
* @param Locale $localeValidator
69-
* @param RegexFactory $versionValidatorFactory
71+
* @param RegexFactory|null $versionValidatorFactory
7072
*/
7173
public function __construct(
7274
Locale $localeValidator,
@@ -100,6 +102,10 @@ public function validate(InputInterface $input)
100102
$this->checkVersionInput(
101103
$input->getOption(Options::CONTENT_VERSION) ?: ''
102104
);
105+
$this->checkNoParentInput(
106+
(bool)$input->getOption(Options::NO_PARENT),
107+
(string)$input->getOption(Options::STRATEGY)
108+
);
103109
}
104110

105111
/**
@@ -108,12 +114,12 @@ public function validate(InputInterface $input)
108114
* @param array $areasInclude
109115
* @param array $areasExclude
110116
* @return void
111-
* @throws \InvalidArgumentException
117+
* @throws InvalidArgumentException
112118
*/
113119
private function checkAreasInput(array $areasInclude, array $areasExclude)
114120
{
115-
if ($areasInclude[0] != 'all' && $areasExclude[0] != 'none') {
116-
throw new \InvalidArgumentException(
121+
if ($areasInclude[0] !== 'all' && $areasExclude[0] !== 'none') {
122+
throw new InvalidArgumentException(
117123
'--area (-a) and --exclude-area cannot be used at the same time'
118124
);
119125
}
@@ -125,12 +131,12 @@ private function checkAreasInput(array $areasInclude, array $areasExclude)
125131
* @param array $themesInclude
126132
* @param array $themesExclude
127133
* @return void
128-
* @throws \InvalidArgumentException
134+
* @throws InvalidArgumentException
129135
*/
130136
private function checkThemesInput(array $themesInclude, array $themesExclude)
131137
{
132-
if ($themesInclude[0] != 'all' && $themesExclude[0] != 'none') {
133-
throw new \InvalidArgumentException(
138+
if ($themesInclude[0] !== 'all' && $themesExclude[0] !== 'none') {
139+
throw new InvalidArgumentException(
134140
'--theme (-t) and --exclude-theme cannot be used at the same time'
135141
);
136142
}
@@ -142,21 +148,21 @@ private function checkThemesInput(array $themesInclude, array $themesExclude)
142148
* @param array $languagesInclude
143149
* @param array $languagesExclude
144150
* @return void
145-
* @throws \InvalidArgumentException
151+
* @throws InvalidArgumentException
146152
*/
147153
private function checkLanguagesInput(array $languagesInclude, array $languagesExclude)
148154
{
149-
if ($languagesInclude[0] != 'all') {
155+
if ($languagesInclude[0] !== 'all') {
150156
foreach ($languagesInclude as $lang) {
151157
if (!$this->localeValidator->isValid($lang)) {
152-
throw new \InvalidArgumentException(
158+
throw new InvalidArgumentException(
153159
$lang .
154160
' argument has invalid value, please run info:language:list for list of available locales'
155161
);
156162
}
157163
}
158-
if ($languagesExclude[0] != 'none') {
159-
throw new \InvalidArgumentException(
164+
if ($languagesExclude[0] !== 'none') {
165+
throw new InvalidArgumentException(
160166
'--language (-l) and --exclude-language cannot be used at the same time'
161167
);
162168
}
@@ -167,7 +173,7 @@ private function checkLanguagesInput(array $languagesInclude, array $languagesEx
167173
* Version input checks
168174
*
169175
* @param string $contentVersion
170-
* @throws \InvalidArgumentException
176+
* @throws InvalidArgumentException
171177
*/
172178
private function checkVersionInput(string $contentVersion): void
173179
{
@@ -179,12 +185,33 @@ private function checkVersionInput(string $contentVersion): void
179185
);
180186

181187
if (!$versionValidator->isValid($contentVersion)) {
182-
throw new \InvalidArgumentException(
188+
throw new InvalidArgumentException(
183189
'Argument "' .
184190
Options::CONTENT_VERSION
185191
. '" has invalid value, content version should contain only characters, digits and dots'
186192
);
187193
}
188194
}
189195
}
196+
197+
/**
198+
* Validate if --no-parent flag could be used with selected strategy
199+
*
200+
* @param bool $noParent
201+
* @param string $strategy
202+
* @throws InvalidArgumentException
203+
*/
204+
private function checkNoParentInput(bool $noParent, string $strategy): void
205+
{
206+
$supportedStrategies = [
207+
'quick' => true,
208+
'standard' => true,
209+
];
210+
211+
if ($noParent && !array_key_exists($strategy, $supportedStrategies)) {
212+
throw new InvalidArgumentException(
213+
sprintf('Argument "%s" is not supported with "%s" strategy', Options::NO_PARENT, $strategy)
214+
);
215+
}
216+
}
190217
}

app/code/Magento/Deploy/Strategy/QuickDeploy.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Deploy\Strategy;
77

8-
use Magento\Deploy\Package\PackagePool;
8+
use Magento\Deploy\Console\DeployStaticOptions as Options;
99
use Magento\Deploy\Package\Package;
10+
use Magento\Deploy\Package\PackagePool;
1011
use Magento\Deploy\Process\Queue;
12+
use function array_key_exists;
1113

1214
/**
1315
* Quick deployment strategy implementation
@@ -51,7 +53,6 @@ public function deploy(array $options)
5153
$groupedPackages = $deployPackages = [];
5254
$packages = $this->packagePool->getPackagesForDeployment($options);
5355
foreach ($packages as $package) {
54-
/** @var Package $package */
5556
if ($package->isVirtual()) {
5657
// skip packages which can not be referenced directly
5758
continue;
@@ -66,10 +67,17 @@ public function deploy(array $options)
6667
$this->preparePackages($level, $levelPackages);
6768
}
6869

70+
$parentCompilationRequested = $options[Options::NO_PARENT] !== true;
71+
$includeThemesMap = array_flip($options[Options::THEME] ?? []);
72+
$excludeThemesMap = array_flip($options[Options::EXCLUDE_THEME] ?? []);
73+
6974
foreach ($groupedPackages as $levelPackages) {
7075
foreach ($levelPackages as $package) {
71-
$this->queue->add($package);
72-
$deployPackages[] = $package;
76+
if ($parentCompilationRequested
77+
|| $this->canDeployTheme($package->getTheme(), $includeThemesMap, $excludeThemesMap)) {
78+
$this->queue->add($package);
79+
$deployPackages[] = $package;
80+
}
7381
}
7482
}
7583

@@ -79,11 +87,13 @@ public function deploy(array $options)
7987
}
8088

8189
/**
90+
* Prepare packages before deploying
91+
*
8292
* @param int $level
8393
* @param Package[] $levelPackages
8494
* @return void
8595
*/
86-
private function preparePackages($level, array $levelPackages)
96+
private function preparePackages(int $level, array $levelPackages): void
8797
{
8898
foreach ($levelPackages as $package) {
8999
$package->aggregate();
@@ -120,7 +130,7 @@ private function preparePackages($level, array $levelPackages)
120130
* @param Package $package
121131
* @return int
122132
*/
123-
private function getInheritanceLevel(Package $package)
133+
private function getInheritanceLevel(Package $package): int
124134
{
125135
$level = $package->getInheritanceLevel();
126136
$packageId = $package->getArea() . '/' . $package->getTheme();
@@ -131,4 +141,28 @@ private function getInheritanceLevel(Package $package)
131141
}
132142
return $level;
133143
}
144+
145+
/**
146+
* Verify if specified theme should be deployed
147+
*
148+
* @param string $theme
149+
* @param array $includedThemesMap
150+
* @param array $excludedEntitiesMap
151+
* @return bool
152+
*/
153+
private function canDeployTheme(string $theme, array $includedThemesMap, array $excludedEntitiesMap): bool
154+
{
155+
$includesAllThemes = array_key_exists('all', $includedThemesMap);
156+
$excludesNoneThemes = array_key_exists('none', $excludedEntitiesMap);
157+
158+
if ($includesAllThemes && $excludesNoneThemes) {
159+
return true;
160+
} elseif (!$excludesNoneThemes) {
161+
return !array_key_exists($theme, $excludedEntitiesMap);
162+
} elseif (!$includesAllThemes) {
163+
return array_key_exists($theme, $includedThemesMap);
164+
}
165+
166+
return true;
167+
}
134168
}

app/code/Magento/Deploy/Strategy/StandardDeploy.php

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

8-
use Magento\Deploy\Package\PackagePool;
8+
use Magento\Deploy\Console\DeployStaticOptions as Options;
99
use Magento\Deploy\Package\Package;
10+
use Magento\Deploy\Package\PackagePool;
1011
use Magento\Deploy\Process\Queue;
1112

1213
/**
@@ -60,12 +61,43 @@ public function deploy(array $options)
6061
$deployedPackages[] = $package;
6162
}
6263

64+
$parentCompilationRequested = $options[Options::NO_PARENT] !== true;
65+
$includeThemesMap = array_flip($options[Options::THEME] ?? []);
66+
$excludeThemesMap = array_flip($options[Options::EXCLUDE_THEME] ?? []);
67+
6368
foreach ($deployedPackages as $package) {
64-
$this->queue->add($package);
69+
if ($parentCompilationRequested
70+
|| $this->canDeployTheme($package->getTheme(), $includeThemesMap, $excludeThemesMap)) {
71+
$this->queue->add($package);
72+
}
6573
}
6674

6775
$this->queue->process();
6876

6977
return $deployedPackages;
7078
}
79+
80+
/**
81+
* Verify if specified theme should be deployed
82+
*
83+
* @param string $theme
84+
* @param array $includedThemesMap
85+
* @param array $excludedEntitiesMap
86+
* @return bool
87+
*/
88+
private function canDeployTheme(string $theme, array $includedThemesMap, array $excludedEntitiesMap): bool
89+
{
90+
$includesAllThemes = array_key_exists('all', $includedThemesMap);
91+
$excludesNoneThemes = array_key_exists('none', $excludedEntitiesMap);
92+
93+
if ($includesAllThemes && $excludesNoneThemes) {
94+
return true;
95+
} elseif (!$excludesNoneThemes) {
96+
return !array_key_exists($theme, $excludedEntitiesMap);
97+
} elseif (!$includesAllThemes) {
98+
return array_key_exists($theme, $includedThemesMap);
99+
}
100+
101+
return true;
102+
}
71103
}

0 commit comments

Comments
 (0)