Ability for FOSElasticaBundle to disable persistence backend logging for population
Update documentation and changelog
This commit is contained in:
parent
6253d3f8df
commit
2029aba76a
|
@ -19,6 +19,7 @@ To generate a changelog summary since the last version, run
|
||||||
* #415: BC BREAK: document indexing occurs in postFlush rather than the pre* events previously.
|
* #415: BC BREAK: document indexing occurs in postFlush rather than the pre* events previously.
|
||||||
* 7d13823: Dropped (broken) support for Symfony <2.3
|
* 7d13823: Dropped (broken) support for Symfony <2.3
|
||||||
* #496: Added support for HTTP headers
|
* #496: Added support for HTTP headers
|
||||||
|
* #528: FOSElasticaBundle will disable Doctrine logging when populating for a large increase in speed
|
||||||
|
|
||||||
* 3.0.0-ALPHA2 (2014-03-17)
|
* 3.0.0-ALPHA2 (2014-03-17)
|
||||||
|
|
||||||
|
|
|
@ -187,9 +187,10 @@ class Configuration implements ConfigurationInterface
|
||||||
->scalarNode('identifier')->defaultValue('id')->end()
|
->scalarNode('identifier')->defaultValue('id')->end()
|
||||||
->arrayNode('provider')
|
->arrayNode('provider')
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
|
|
||||||
->scalarNode('batch_size')->defaultValue(100)->end()
|
->scalarNode('batch_size')->defaultValue(100)->end()
|
||||||
->scalarNode('clear_object_manager')->defaultTrue()->end()
|
->scalarNode('clear_object_manager')->defaultTrue()->end()
|
||||||
|
->scalarNode('disable_logger')->defaultValue('%kernel.debug%')->end()
|
||||||
|
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
|
||||||
->scalarNode('service')->end()
|
->scalarNode('service')->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
|
|
@ -23,6 +23,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
{
|
{
|
||||||
parent::__construct($objectPersister, $objectClass, array_merge(array(
|
parent::__construct($objectPersister, $objectClass, array_merge(array(
|
||||||
'clear_object_manager' => true,
|
'clear_object_manager' => true,
|
||||||
|
'disable_logging' => false,
|
||||||
'ignore_errors' => false,
|
'ignore_errors' => false,
|
||||||
'query_builder_method' => 'createQueryBuilder',
|
'query_builder_method' => 'createQueryBuilder',
|
||||||
), $options));
|
), $options));
|
||||||
|
@ -35,12 +36,17 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
*/
|
*/
|
||||||
public function populate(\Closure $loggerClosure = null, array $options = array())
|
public function populate(\Closure $loggerClosure = null, array $options = array())
|
||||||
{
|
{
|
||||||
|
if (!$this->options['disable_logging']) {
|
||||||
|
$logger = $this->disableLogging();
|
||||||
|
}
|
||||||
|
|
||||||
$queryBuilder = $this->createQueryBuilder();
|
$queryBuilder = $this->createQueryBuilder();
|
||||||
$nbObjects = $this->countObjects($queryBuilder);
|
$nbObjects = $this->countObjects($queryBuilder);
|
||||||
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
||||||
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
||||||
$batchSize = isset($options['batch-size']) ? intval($options['batch-size']) : $this->options['batch_size'];
|
$batchSize = isset($options['batch-size']) ? intval($options['batch-size']) : $this->options['batch_size'];
|
||||||
$ignoreErrors = isset($options['ignore-errors']) ? $options['ignore-errors'] : $this->options['ignore_errors'];
|
$ignoreErrors = isset($options['ignore-errors']) ? $options['ignore-errors'] : $this->options['ignore_errors'];
|
||||||
|
$manager = $this->managerRegistry->getManagerForClass($this->objectClass);
|
||||||
|
|
||||||
for (; $offset < $nbObjects; $offset += $batchSize) {
|
for (; $offset < $nbObjects; $offset += $batchSize) {
|
||||||
if ($loggerClosure) {
|
if ($loggerClosure) {
|
||||||
|
@ -61,7 +67,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->options['clear_object_manager']) {
|
if ($this->options['clear_object_manager']) {
|
||||||
$this->managerRegistry->getManagerForClass($this->objectClass)->clear();
|
$manager->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep($sleep);
|
usleep($sleep);
|
||||||
|
@ -75,6 +81,10 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
$loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $this->getMemoryUsage()));
|
$loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $this->getMemoryUsage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->options['disable_logging']) {
|
||||||
|
$this->enableLogging($logger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +95,21 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
*/
|
*/
|
||||||
protected abstract function countObjects($queryBuilder);
|
protected abstract function countObjects($queryBuilder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables logging and returns the logger that was previously set.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected abstract function disableLogging();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reenables the logger with the previously returned logger from disableLogging();
|
||||||
|
*
|
||||||
|
* @param mixed $logger
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected abstract function enableLogging($logger);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a slice of objects using the query builder.
|
* Fetches a slice of objects using the query builder.
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,40 @@ use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
||||||
|
|
||||||
class Provider extends AbstractProvider
|
class Provider extends AbstractProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Disables logging and returns the logger that was previously set.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function disableLogging()
|
||||||
|
{
|
||||||
|
$configuration = $this->managerRegistry
|
||||||
|
->getManagerForClass($this->objectClass)
|
||||||
|
->getConnection()
|
||||||
|
->getConfiguration();
|
||||||
|
|
||||||
|
$logger = $configuration->getLoggerCallable();
|
||||||
|
$configuration->setLoggerCallable(null);
|
||||||
|
|
||||||
|
return $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reenables the logger with the previously returned logger from disableLogging();
|
||||||
|
*
|
||||||
|
* @param mixed $logger
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function enableLogging($logger)
|
||||||
|
{
|
||||||
|
$configuration = $this->managerRegistry
|
||||||
|
->getManagerForClass($this->objectClass)
|
||||||
|
->getConnection()
|
||||||
|
->getConfiguration();
|
||||||
|
|
||||||
|
$configuration->setLoggerCallable($logger);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see FOS\ElasticaBundle\Doctrine\AbstractProvider::countObjects()
|
* @see FOS\ElasticaBundle\Doctrine\AbstractProvider::countObjects()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace FOS\ElasticaBundle\Doctrine\ORM;
|
namespace FOS\ElasticaBundle\Doctrine\ORM;
|
||||||
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
|
||||||
use FOS\ElasticaBundle\Doctrine\AbstractProvider;
|
use FOS\ElasticaBundle\Doctrine\AbstractProvider;
|
||||||
use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
||||||
|
|
||||||
|
@ -10,6 +11,40 @@ class Provider extends AbstractProvider
|
||||||
{
|
{
|
||||||
const ENTITY_ALIAS = 'a';
|
const ENTITY_ALIAS = 'a';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables logging and returns the logger that was previously set.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function disableLogging()
|
||||||
|
{
|
||||||
|
$configuration = $this->managerRegistry
|
||||||
|
->getManagerForClass($this->objectClass)
|
||||||
|
->getConnection()
|
||||||
|
->getConfiguration();
|
||||||
|
|
||||||
|
$logger = $configuration->getSQLLogger();
|
||||||
|
$configuration->setSQLLogger(null);
|
||||||
|
|
||||||
|
return $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reenables the logger with the previously returned logger from disableLogging();
|
||||||
|
*
|
||||||
|
* @param mixed $logger
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function enableLogging($logger)
|
||||||
|
{
|
||||||
|
$configuration = $this->managerRegistry
|
||||||
|
->getManagerForClass($this->objectClass)
|
||||||
|
->getConnection()
|
||||||
|
->getConfiguration();
|
||||||
|
|
||||||
|
$configuration->setSQLLogger($logger);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see FOS\ElasticaBundle\Doctrine\AbstractProvider::countObjects()
|
* @see FOS\ElasticaBundle\Doctrine\AbstractProvider::countObjects()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -188,6 +188,21 @@ persistence configuration.
|
||||||
identifier: searchId
|
identifier: searchId
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Turning on the persistence backend logger in production
|
||||||
|
|
||||||
|
FOSElasticaBundle will turn of your persistence backend's logging configuration by default
|
||||||
|
when Symfony2 is not in debug mode.
|
||||||
|
|
||||||
|
To enable the logger (turn off this behaviour) set disable_logger to false for the
|
||||||
|
provider
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
user:
|
||||||
|
persistence:
|
||||||
|
provider:
|
||||||
|
disable_logger: false
|
||||||
|
```
|
||||||
|
|
||||||
Listener Configuration
|
Listener Configuration
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue