Skip to content

Commit

Permalink
Revert "BAP-22165: Improve oro:platform:update commands performance (…
Browse files Browse the repository at this point in the history
…#37464)" (#37706)

This reverts commit a0c6d39c5649cda9e3e5dc0fda62a48a82aaede0.
  • Loading branch information
anyt authored Feb 29, 2024
1 parent acc5acc commit 04ee704
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 657 deletions.
67 changes: 62 additions & 5 deletions src/Oro/Bundle/EntityConfigBundle/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Oro\Bundle\EntityConfigBundle\Command;

use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Oro\Bundle\EntityConfigBundle\Tools\ConfigLoader;
use Oro\Bundle\EntityConfigBundle\Tools\ConfigLogger;
use Oro\Component\Log\OutputLogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Updates configuration data for entities.
* Command uses config loader that utilizes DBAL based update approach.
*/
class UpdateCommand extends Command
{
Expand All @@ -31,15 +34,46 @@ public function __construct(ConfigLoader $configLoader)
public function configure()
{
$this
->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite config option values')
->addOption(
'filter',
null,
InputOption::VALUE_OPTIONAL,
'Regular expression to filter entities by their class name'
)
->addOption(
'dry-run',
null,
InputOption::VALUE_NONE,
'Output modifications without applying them'
)
->setDescription('Updates configuration data for entities.')
->setHelp(
<<<'HELP'
The <info>%command.name%</info> command reads entities configuration
from their classes annotations and merges them into DB.
!!! For internal use only
The <info>%command.name%</info> command parses tracking logs.
<info>php %command.full_name%</info>
The <info>--force</info> option can be used to force overriding of config option values.
<info>php %command.full_name% --force</info>
The <info>--dry-run</info> option outputs modifications without actually applying them.
<info>php %command.full_name% --dry-run</info>
A regular expression provided with the <info>--filter</info> option will be used to filter entities
by their class names:
<info>php %command.full_name% --filter=<regexp></info>
<info>php %command.full_name% --filter='Oro\\Bundle\\User*'</info>
<info>php %command.full_name% --filter='^Oro\\(.*)\\Region$'</info>

HELP
)
->addUsage('--force')
->addUsage('--dry-run')
->addUsage('--filter=<regexp>')
;
}

Expand All @@ -48,8 +82,31 @@ public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Update configuration data for entities');

$filter = $input->getOption('filter');
if ($filter) {
$filter = function ($doctrineAllMetadata) use ($filter) {
return array_filter(
$doctrineAllMetadata,
function ($item) use ($filter) {
/** @var ClassMetadataInfo $item */
return preg_match('/' . str_replace('\\', '\\\\', $filter) . '/', $item->getName());
}
);
};
}

$verbosity = $output->getVerbosity();
if (!$input->getOption('dry-run')) {
$verbosity--;
}
$logger = new ConfigLogger(new OutputLogger($output, true, $verbosity));
/** @var ConfigLoader $loader */
$this->configLoader->load();
$this->configLoader->load(
$input->getOption('force'),
$filter,
$logger,
$input->getOption('dry-run')
);

return Command::SUCCESS;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Oro/Bundle/EntityConfigBundle/Config/ConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,7 @@ private function saveFieldConfig(ConfigInterface $config, $localCacheOnly = fals
if (isset($this->fields[$scope][$className])) {
$entry = $this->fields[$scope][$className];
} else {
$entry = !$localCacheOnly
? $this->cacheFetch($this->getFieldConfigsCacheKey($className, $scope))
: false;
$entry = $this->cacheFetch($this->getFieldConfigsCacheKey($className, $scope));
if (false === $entry) {
$entry = [];
}
Expand Down
58 changes: 22 additions & 36 deletions src/Oro/Bundle/EntityConfigBundle/Config/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class ConfigManager
/** @var ConfigProviderBag */
private $providerBag;

/** @var bool */
private $localCacheOnly = false;

/** @var array */
protected $originalValues = [];

Expand All @@ -53,19 +50,12 @@ class ConfigManager
/** @var array */
protected $configChangeSets = [];

private ?bool $dataBaseReadyToWork = null;

public function __construct(
protected ConfigCache $cache,
protected ContainerInterface $locator,
) {
}

public function useLocalCacheOnly()
{
$this->localCacheOnly = true;
}

/**
* Gets the EntityManager responsible to work with configuration entities
* IMPORTANT: configuration entities may use own entity manager which may be not equal the default entity manager
Expand Down Expand Up @@ -105,11 +95,7 @@ public function setProviderBag(ConfigProviderBag $providerBag)
*/
public function isDatabaseReadyToWork()
{
if (null === $this->dataBaseReadyToWork) {
$this->dataBaseReadyToWork = $this->getModelManager()->checkDatabase();
}

return $this->dataBaseReadyToWork;
return $this->getModelManager()->checkDatabase();
}

protected function getMetadataFactory(): MetadataFactory
Expand Down Expand Up @@ -207,7 +193,7 @@ public function isHiddenModel($className, $fieldName = null)
*/
public function hasConfig($className, $fieldName = null)
{
if (!$this->isDatabaseReadyToWork()) {
if (!$this->getModelManager()->checkDatabase()) {
return false;
}

Expand Down Expand Up @@ -281,9 +267,9 @@ public function createFieldConfigByModel(FieldConfigModel $fieldConfigModel, str
public function getEntityConfig($scope, $className)
{
$className = ClassUtils::getRealClass($className);
$config = $this->cache->getEntityConfig($scope, $className, $this->localCacheOnly);
$config = $this->cache->getEntityConfig($scope, $className);
if (!$config) {
if (!$this->isDatabaseReadyToWork()) {
if (!$this->getModelManager()->checkDatabase()) {
throw $this->createDatabaseNotSyncedException();
}

Expand All @@ -296,7 +282,7 @@ public function getEntityConfig($scope, $className)
$this->getModelManager()->getEntityModel($className)->toArray($scope)
);
// put to a cache
$this->cache->saveConfig($config, $this->localCacheOnly);
$this->cache->saveConfig($config);
}

// for calculate change set
Expand All @@ -318,9 +304,9 @@ public function getEntityConfig($scope, $className)
*/
public function getFieldConfig($scope, $className, $fieldName)
{
$config = $this->cache->getFieldConfig($scope, $className, $fieldName, $this->localCacheOnly);
$config = $this->cache->getFieldConfig($scope, $className, $fieldName);
if (!$config) {
if (!$this->isDatabaseReadyToWork()) {
if (!$this->getModelManager()->checkDatabase()) {
throw $this->createDatabaseNotSyncedException();
}

Expand All @@ -337,7 +323,7 @@ public function getFieldConfig($scope, $className, $fieldName)
$model->toArray($scope)
);
// put to a cache
$this->cache->saveConfig($config, $this->localCacheOnly);
$this->cache->saveConfig($config);
}

// for calculate change set
Expand Down Expand Up @@ -1330,14 +1316,14 @@ protected function mapEntities($callback, $scope, $withHidden)
{
$result = [];

$entities = $this->cache->getEntities($this->localCacheOnly);
$entities = $this->cache->getEntities();
if (null !== $entities) {
foreach ($entities as $class => $data) {
if ($withHidden || !$data['h']) {
$result[] = $callback($scope, $class);
}
}
} elseif ($this->isDatabaseReadyToWork()) {
} elseif ($this->getModelManager()->checkDatabase()) {
$models = $this->getModelManager()->getModels();
$entities = [];
/** @var EntityConfigModel $model */
Expand All @@ -1353,7 +1339,7 @@ protected function mapEntities($callback, $scope, $withHidden)
$result[] = $callback($scope, $class);
}
}
$this->cache->saveEntities($entities, $this->localCacheOnly);
$this->cache->saveEntities($entities);
}

return $result;
Expand All @@ -1368,8 +1354,8 @@ protected function findEntity($className)
{
$result = null;

$entities = $this->cache->getEntities($this->localCacheOnly);
if (null === $entities && $this->isDatabaseReadyToWork()) {
$entities = $this->cache->getEntities();
if (null === $entities && $this->getModelManager()->checkDatabase()) {
$models = $this->getModelManager()->getModels();
$entities = [];
/** @var EntityConfigModel $model */
Expand All @@ -1382,7 +1368,7 @@ protected function findEntity($className)
'h' => $isHidden
];
}
$this->cache->saveEntities($entities, $this->localCacheOnly);
$this->cache->saveEntities($entities);
}
if (null !== $entities && isset($entities[$className])) {
$result = $entities[$className];
Expand All @@ -1403,14 +1389,14 @@ protected function mapFields($callback, $scope, $className, $withHidden)
{
$result = [];

$fields = $this->cache->getFields($className, $this->localCacheOnly);
$fields = $this->cache->getFields($className);
if (null !== $fields) {
foreach ($fields as $field => $data) {
if ($withHidden || !$data['h']) {
$result[] = $callback($scope, $className, $field, $data['t']);
}
}
} elseif ($this->isDatabaseReadyToWork()) {
} elseif ($this->getModelManager()->checkDatabase()) {
$models = $this->getModelManager()->getModels($className);
$fields = [];
/** @var FieldConfigModel $model */
Expand All @@ -1428,7 +1414,7 @@ protected function mapFields($callback, $scope, $className, $withHidden)
$result[] = $callback($scope, $className, $field, $type);
}
}
$this->cache->saveFields($className, $fields, $this->localCacheOnly);
$this->cache->saveFields($className, $fields);
}

return $result;
Expand All @@ -1444,8 +1430,8 @@ protected function findField($className, $fieldName)
{
$result = null;

$fields = $this->cache->getFields($className, $this->localCacheOnly);
if (null === $fields && $this->isDatabaseReadyToWork()) {
$fields = $this->cache->getFields($className);
if (null === $fields && $this->getModelManager()->checkDatabase()) {
$models = $this->getModelManager()->getModels($className);
$fields = [];
/** @var FieldConfigModel $model */
Expand All @@ -1460,7 +1446,7 @@ protected function findField($className, $fieldName)
't' => $type,
];
}
$this->cache->saveFields($className, $fields, $this->localCacheOnly);
$this->cache->saveFields($className, $fields);
}
if (null !== $fields && isset($fields[$fieldName])) {
$result = $fields[$fieldName];
Expand All @@ -1481,7 +1467,7 @@ protected function isConfigurableEntity($className)
$isConfigurable = $this->cache->getConfigurable($className);
if (null === $isConfigurable) {
$isConfigurable = (null !== $this->getModelManager()->findEntityModel($className));
$this->cache->saveConfigurable($isConfigurable, $className, null, $this->localCacheOnly);
$this->cache->saveConfigurable($isConfigurable, $className);
}

return $isConfigurable;
Expand All @@ -1500,7 +1486,7 @@ protected function isConfigurableField($className, $fieldName)
$isConfigurable = $this->cache->getConfigurable($className, $fieldName);
if (null === $isConfigurable) {
$isConfigurable = (null !== $this->getModelManager()->findFieldModel($className, $fieldName));
$this->cache->saveConfigurable($isConfigurable, $className, $fieldName, $this->localCacheOnly);
$this->cache->saveConfigurable($isConfigurable, $className, $fieldName);
}

return $isConfigurable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
use Oro\Bundle\EntityConfigBundle\Migration\UpdateEntityConfigMigration;
use Oro\Bundle\EntityConfigBundle\Migration\WarmUpEntityConfigCacheMigration;
use Oro\Bundle\EntityConfigBundle\Tools\CommandExecutor;
use Oro\Bundle\InstallerBundle\CommandExecutor as InstallerCommandExecutor;
use Oro\Bundle\MigrationBundle\Event\PostMigrationEvent;

/**
* Entity config update preUp, postUp migrations setup.
*/
class PostUpMigrationListener
{
/**
Expand Down Expand Up @@ -38,12 +34,8 @@ public function updateConfigs(PostMigrationEvent $event)
*/
public function warmUpCache(PostMigrationEvent $event)
{
if (!InstallerCommandExecutor::isCommandRunning('oro:install')
&& !InstallerCommandExecutor::isCommandRunning('oro:platform:update')
) {
$event->addMigration(
new WarmUpEntityConfigCacheMigration($this->commandExecutor)
);
}
$event->addMigration(
new WarmUpEntityConfigCacheMigration($this->commandExecutor)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:

Oro\Bundle\EntityConfigBundle\Command\UpdateCommand:
arguments:
- '@Oro\Bundle\EntityConfigBundle\Tools\ConfigLoader'
- '@oro_entity_config.config_loader'
tags:
- { name: console.command }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ services:
- '@.inner'
- '@oro_cache.oro_data_cache_manager'

Oro\Bundle\EntityConfigBundle\Tools\ConfigLoader:
oro_entity_config.config_loader:
class: Oro\Bundle\EntityConfigBundle\Tools\ConfigLoader
arguments:
- '@oro_entity_config.config_manager'
- '@oro_entity_config.entity_manager_bag'
- '@oro_entity_config.metadata.annotation_metadata_factory'
- '@oro_entity_config.configuration_handler'
- '@oro_entity_config.provider_bag'
- '@oro_entity_config.config_cache_impl'

oro_entity_config.cache:
public: false
Expand Down
Loading

0 comments on commit 04ee704

Please sign in to comment.