Permalink
Browse files

Merge pull request #2585 from gillesbourgeat/improve-propel-cache

Improve propel cache
  • Loading branch information...
gillesbourgeat committed Nov 22, 2018
2 parents 3a8fafb + a03b08b commit 3d95d5f2ebc45002a1d8548c65828a34fc8f6860
@@ -75,6 +75,11 @@
define('THELIA_SETUP_WIZARD_DIRECTORY', THELIA_ROOT . 'web' . DS . 'install' . DS);
}
// this will be used in our Propel model builders
if (!defined('THELIA_PROPEL_BUILD_PATH')) {
define('THELIA_PROPEL_BUILD_PATH', THELIA_CACHE_DIR . 'propel' . DS . 'model' . DS);
}
if (!file_exists(THELIA_CONF_DIR . 'database.yml') && !defined('THELIA_INSTALL_MODE')) {
$sapi = php_sapi_name();
if (substr($sapi, 0, 3) == 'cli') {
@@ -260,7 +260,6 @@
</service>
<service id="propel.listener" class="Thelia\Core\EventListener\PropelListener">
<argument type="service" id="thelia.propel.init"/>
<argument>%thelia.propel.table_map_classes%</argument>
<tag name="kernel.event_subscriber"/>
</service>
@@ -69,12 +69,7 @@ public function build(ContainerBuilder $container)
->addCompilerPass(new CurrencyConverterProviderPass())
->addCompilerPass(new RegisterListenersPass())
->addCompilerPass(new PropelPass(
THELIA_CACHE_DIR
. ($container->hasParameter("kernel.environment")
? ('/' . $container->getParameter("kernel.environment"))
: ''
)
. '/propel/model/'
THELIA_PROPEL_BUILD_PATH
))
;
}
@@ -21,25 +21,17 @@
*/
class PropelListener implements EventSubscriberInterface
{
/**
* Propel initialization service.
* @var PropelInitService
*/
protected $propelInitService;
/**
* Table map classes to be built.
* @var string[]
*/
protected $tableMapClasses = [];
/**
* @param PropelInitService $propelInitService Propel initialization service.
* @param string[] $tableMapClasses Table map classes to be built.
*/
public function __construct(PropelInitService $propelInitService, array $tableMapClasses = [])
public function __construct(array $tableMapClasses = [])
{
$this->propelInitService = $propelInitService;
$this->tableMapClasses = $tableMapClasses;
}
@@ -59,12 +51,4 @@ public function buildTableMaps()
call_user_func([$tableMapClass, 'buildTableMap']);
}
}
/**
* Rebuild the cache.
*/
public function rebuildCache()
{
$this->propelInitService->init();
}
}
@@ -26,9 +26,7 @@
public function getClassFilePath()
{
return rtrim((new Filesystem())->makePathRelative(
THELIA_CACHE_DIR
. (defined('THELIA_PROPEL_BUILDER_ENVIRONMENT') ? THELIA_PROPEL_BUILDER_ENVIRONMENT : '')
. DS . 'propel' . DS . 'model' . DS
THELIA_PROPEL_BUILD_PATH
. parent::getClassFilePath(),
THELIA_ROOT
), '/');
@@ -135,7 +135,7 @@ public function getPropelSchemaDir()
*/
public function getPropelModelDir()
{
return $this->getPropelCacheDir() . 'model' . DS;
return THELIA_PROPEL_BUILD_PATH;
}
/**
@@ -261,6 +261,8 @@ public function buildPropelGlobalSchema()
return;
}
$hash = '';
$fs->mkdir($this->getPropelSchemaDir());
$schemaCombiner = new SchemaCombiner(
@@ -282,7 +284,11 @@ public function buildPropelGlobalSchema()
$schemaCombiner->getCombinedDocument($database)->saveXML(),
$databaseSchemaResources
);
$hash .= md5(file_get_contents($this->getPropelSchemaDir() . $database .'.schema.xml'));
}
$fs->dumpFile($this->getPropelCacheDir() . 'hash', $hash);
}
/**
@@ -293,18 +299,26 @@ public function buildPropelModels()
{
$fs = new Filesystem();
// TODO: caching rules ?
if ($fs->exists($this->getPropelModelDir())) {
// cache testing
if ($fs->exists($this->getPropelModelDir() . 'hash')
&& file_get_contents($this->getPropelCacheDir() . 'hash') === file_get_contents($this->getPropelModelDir() . 'hash')) {
return;
}
$fs->remove($this->getPropelModelDir());
$this->runCommand(
new ModelBuildCommand(),
[
'--config-dir' => $this->getPropelConfigDir(),
'--schema-dir' => $this->getPropelSchemaDir(),
]
);
$fs->copy(
$this->getPropelCacheDir() . 'hash',
$this->getPropelModelDir() . 'hash'
);
}
/**
@@ -340,11 +354,6 @@ public function init($force = false)
return false;
}
// this will be used in our Propel model builders
if (!defined('THELIA_PROPEL_BUILDER_ENVIRONMENT')) {
define('THELIA_PROPEL_BUILDER_ENVIRONMENT', $this->environment);
}
$this->buildPropelConfig();
$this->buildPropelInitFile();

0 comments on commit 3d95d5f

Please sign in to comment.