Skip to content

Commit 83eac3e

Browse files
committed
MAGETWO-52660: Improve performance of static assets deployment
- MAGETWO-57913: Mysql connections is lost if forked process
1 parent 6c7ca54 commit 83eac3e

13 files changed

+163
-187
lines changed

app/code/Magento/Deploy/Model/Deploy/DeployInterface.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ interface DeployInterface
1515
* @return int
1616
*/
1717
public function deploy($area, $themePath, $locale);
18-
19-
/**
20-
* @param array $options
21-
* @return void
22-
*/
23-
public function setOptions(array $options);
2418
}

app/code/Magento/Deploy/Model/Deploy/LocaleDeploy.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class LocaleDeploy implements DeployInterface
152152
* @param \Magento\Framework\View\DesignInterfaceFactory $designFactory
153153
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
154154
* @param array $alternativeSources
155+
* @param array $options
155156
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
156157
*/
157158
public function __construct(
@@ -169,7 +170,8 @@ public function __construct(
169170
Files $filesUtil,
170171
\Magento\Framework\View\DesignInterfaceFactory $designFactory,
171172
\Magento\Framework\Locale\ResolverInterface $localeResolver,
172-
array $alternativeSources
173+
array $alternativeSources,
174+
$options = []
173175
) {
174176
$this->output = $output;
175177
$this->assetRepo = $assetRepo;
@@ -191,6 +193,7 @@ function (AlternativeSourceInterface $alternativeSource) {
191193
);
192194
$this->designFactory = $designFactory;
193195
$this->localeResolver = $localeResolver;
196+
$this->options = $options;
194197
}
195198

196199
/**
@@ -247,14 +250,6 @@ public function deploy($area, $themePath, $locale)
247250
return $this->errorCount ? Cli::RETURN_FAILURE : Cli::RETURN_SUCCESS;
248251
}
249252

250-
/**
251-
* {@inheritdoc}
252-
*/
253-
public function setOptions(array $options)
254-
{
255-
$this->options = $options;
256-
}
257-
258253
/**
259254
* @param string $area
260255
* @param string $themePath

app/code/Magento/Deploy/Model/Deploy/LocaleQuickDeploy.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ class LocaleQuickDeploy implements DeployInterface
4141
/**
4242
* @param Filesystem $filesystem
4343
* @param OutputInterface $output
44+
* @param array $options
4445
*/
45-
public function __construct(\Magento\Framework\Filesystem $filesystem, OutputInterface $output)
46+
public function __construct(\Magento\Framework\Filesystem $filesystem, OutputInterface $output, $options = [])
4647
{
4748
$this->filesystem = $filesystem;
4849
$this->output = $output;
50+
$this->options = $options;
4951
}
5052

5153
/**
@@ -110,14 +112,6 @@ public function deploy($area, $themePath, $locale)
110112
return Cli::RETURN_SUCCESS;
111113
}
112114

113-
/**
114-
* {@inheritdoc}
115-
*/
116-
public function setOptions(array $options)
117-
{
118-
$this->options = $options;
119-
}
120-
121115
/**
122116
* @param string $path
123117
* @return void

app/code/Magento/Deploy/Model/DeployManager.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Console\Output\OutputInterface;
1111
use Magento\Deploy\Console\Command\DeployStaticOptionsInterface as Options;
1212
use Magento\Deploy\Model\Deploy\TemplateMinifier;
13+
use \Magento\Framework\App\State;
1314

1415
class DeployManager
1516
{
@@ -58,12 +59,18 @@ class DeployManager
5859
*/
5960
private $idDryRun;
6061

62+
/**
63+
* @var State
64+
*/
65+
private $state;
66+
6167
/**
6268
* @param OutputInterface $output
6369
* @param StorageInterface $versionStorage
6470
* @param DeployStrategyProviderFactory $deployStrategyProviderFactory
6571
* @param ProcessQueueManager $processQueueManager
6672
* @param TemplateMinifier $templateMinifier
73+
* @param State $state
6774
* @param array $options
6875
*/
6976
public function __construct(
@@ -72,6 +79,7 @@ public function __construct(
7279
DeployStrategyProviderFactory $deployStrategyProviderFactory,
7380
ProcessQueueManager $processQueueManager,
7481
TemplateMinifier $templateMinifier,
82+
State $state,
7583
array $options
7684
) {
7785
$this->output = $output;
@@ -80,6 +88,7 @@ public function __construct(
8088
$this->deployStrategyProviderFactory = $deployStrategyProviderFactory;
8189
$this->processQueueManager = $processQueueManager;
8290
$this->templateMinifier = $templateMinifier;
91+
$this->state = $state;
8392
}
8493

8594
/**
@@ -119,7 +128,11 @@ public function deploy()
119128
$locales = array_keys($package);
120129
list($area, $themePath) = current($package);
121130
foreach ($strategyProvider->getDeployStrategies($area, $themePath, $locales) as $locale => $strategy) {
122-
$result |= $strategy->deploy($area, $themePath, $locale);
131+
$result |= $this->state->emulateAreaCode(
132+
$area,
133+
[$strategy, 'deploy'],
134+
[$area, $themePath, $locale]
135+
);
123136
}
124137
}
125138
}
@@ -157,7 +170,7 @@ private function runInParallel(DeployStrategyProvider $strategyProvider)
157170
$dependentStrategy = [];
158171
foreach ($strategyProvider->getDeployStrategies($area, $themePath, $locales) as $locale => $strategy) {
159172
$deploymentFunc = function () use ($area, $themePath, $locale, $strategy) {
160-
return $strategy->deploy($area, $themePath, $locale);
173+
return $this->state->emulateAreaCode($area, [$strategy, 'deploy'], [$area, $themePath, $locale]);
161174
};
162175
if (null === $baseStrategy) {
163176
$baseStrategy = $deploymentFunc;

app/code/Magento/Deploy/Model/DeployStrategyFactory.php

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

99
use Magento\Deploy\Model\Deploy\DeployInterface;
10-
use Magento\Framework\App\ObjectManagerFactory;
11-
use Magento\Framework\App\State;
10+
use Magento\Framework\ObjectManagerInterface;
1211

1312
class DeployStrategyFactory
1413
{
@@ -23,25 +22,19 @@ class DeployStrategyFactory
2322
const DEPLOY_STRATEGY_QUICK = 'quick';
2423

2524
/**
26-
* @var ObjectManagerFactory
25+
* @param ObjectManagerInterface $objectManager
2726
*/
28-
private $objectManagerFactory;
29-
30-
/**
31-
* @param ObjectManagerFactory $objectManagerFactory
32-
*/
33-
public function __construct(ObjectManagerFactory $objectManagerFactory)
27+
public function __construct(ObjectManagerInterface $objectManager)
3428
{
35-
$this->objectManagerFactory = $objectManagerFactory;
29+
$this->objectManager = $objectManager;
3630
}
3731

3832
/**
39-
* @param string $areaCode
4033
* @param string $type
4134
* @param array $arguments
4235
* @return DeployInterface
4336
*/
44-
public function create($areaCode, $type, array $arguments = [])
37+
public function create($type, array $arguments = [])
4538
{
4639
$strategyMap = [
4740
self::DEPLOY_STRATEGY_STANDARD => Deploy\LocaleDeploy::class,
@@ -51,9 +44,7 @@ public function create($areaCode, $type, array $arguments = [])
5144
if (!isset($strategyMap[$type])) {
5245
throw new \InvalidArgumentException('Wrong deploy strategy type: ' . $type);
5346
}
54-
$objectManager = $this->objectManagerFactory->create([State::PARAM_MODE => State::MODE_PRODUCTION]);
55-
$objectManager->get(State::class)->setAreaCode($areaCode);
5647

57-
return $objectManager->create($strategyMap[$type], $arguments);
48+
return $this->objectManager->create($strategyMap[$type], $arguments);
5849
}
5950
}

app/code/Magento/Deploy/Model/DeployStrategyProvider.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515

1616
class DeployStrategyProvider
1717
{
18-
/**
19-
* @var DeployInterface[]
20-
*/
21-
private $deployStrategies;
22-
2318
/**
2419
* @var RulePool
2520
*/
@@ -86,7 +81,7 @@ public function getDeployStrategies($area, $themePath, array $locales)
8681
{
8782
if (count($locales) == 1) {
8883
$locale = current($locales);
89-
return [$locale => $this->getDeployStrategy($area, DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD)];
84+
return [$locale => $this->getDeployStrategy(DeployStrategyFactory::DEPLOY_STRATEGY_STANDARD)];
9085
}
9186

9287
$baseLocale = null;
@@ -114,7 +109,7 @@ public function getDeployStrategies($area, $themePath, array $locales)
114109
);
115110

116111
return array_map(function ($strategyType) use ($area, $baseLocale) {
117-
return $this->getDeployStrategy($area, $strategyType, $baseLocale);
112+
return $this->getDeployStrategy($strategyType, $baseLocale);
118113
}, $deployStrategies);
119114
}
120115

@@ -178,29 +173,20 @@ private function getFallbackRule()
178173
}
179174

180175
/**
181-
* @param string $area
182176
* @param string $type
183177
* @param null|string $baseLocale
184178
* @return DeployInterface
185179
*/
186-
private function getDeployStrategy($area, $type, $baseLocale = null)
180+
private function getDeployStrategy($type, $baseLocale = null)
187181
{
188-
$key = $area . '-' . $type;
189-
if (!isset($this->deployStrategies[$key])) {
190-
$this->deployStrategies[$key] = $this->deployStrategyFactory->create(
191-
$area,
192-
$type,
193-
['output' => $this->output]
194-
);
195-
}
196-
197-
$deployStrategy = $this->deployStrategies[$key];
198182
$options = $this->options;
199183
if ($baseLocale) {
200184
$options[DeployManager::DEPLOY_BASE_LOCALE] = $baseLocale;
201185
}
202-
$deployStrategy->setOptions($options);
203186

204-
return $deployStrategy;
187+
return $this->deployStrategyFactory->create(
188+
$type,
189+
['output' => $this->output, 'options' => $options]
190+
);
205191
}
206192
}

app/code/Magento/Deploy/Model/Process/ResourceConnectionProvider.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/code/Magento/Deploy/Model/ProcessQueueManager.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Deploy\Model;
88

9-
use Magento\Deploy\Model\Process\ResourceConnectionProvider;
9+
use Magento\Framework\App\ResourceConnection;
1010

1111
class ProcessQueueManager
1212
{
@@ -31,18 +31,18 @@ class ProcessQueueManager
3131
private $processManager;
3232

3333
/**
34-
* @var ResourceConnectionProvider
34+
* @var ResourceConnection
3535
*/
36-
private $resourceConnectionProvider;
36+
private $resourceConnection;
3737

3838
/**
3939
* @param ProcessManager $processManager
40-
* @param ResourceConnectionProvider $resourceConnectionProvider
40+
* @param ResourceConnection $resourceConnection
4141
*/
42-
public function __construct(ProcessManager $processManager, ResourceConnectionProvider $resourceConnectionProvider)
42+
public function __construct(ProcessManager $processManager, ResourceConnection $resourceConnection)
4343
{
4444
$this->processManager = $processManager;
45-
$this->resourceConnectionProvider = $resourceConnectionProvider;
45+
$this->resourceConnection = $resourceConnection;
4646
}
4747

4848
/**
@@ -98,7 +98,7 @@ public function process()
9898
}
9999
usleep(5000);
100100
}
101-
$this->resourceConnectionProvider->get()->closeConnection();
101+
$this->resourceConnection->closeConnection();
102102

103103
return $returnStatus;
104104
}

0 commit comments

Comments
 (0)