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.
|
||||
* 7d13823: Dropped (broken) support for Symfony <2.3
|
||||
* #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)
|
||||
|
||||
|
|
|
@ -187,9 +187,10 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('identifier')->defaultValue('id')->end()
|
||||
->arrayNode('provider')
|
||||
->children()
|
||||
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
|
||||
->scalarNode('batch_size')->defaultValue(100)->end()
|
||||
->scalarNode('clear_object_manager')->defaultTrue()->end()
|
||||
->scalarNode('disable_logger')->defaultValue('%kernel.debug%')->end()
|
||||
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
|
||||
->scalarNode('service')->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
@ -23,6 +23,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
{
|
||||
parent::__construct($objectPersister, $objectClass, array_merge(array(
|
||||
'clear_object_manager' => true,
|
||||
'disable_logging' => false,
|
||||
'ignore_errors' => false,
|
||||
'query_builder_method' => 'createQueryBuilder',
|
||||
), $options));
|
||||
|
@ -35,12 +36,17 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
*/
|
||||
public function populate(\Closure $loggerClosure = null, array $options = array())
|
||||
{
|
||||
if (!$this->options['disable_logging']) {
|
||||
$logger = $this->disableLogging();
|
||||
}
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder();
|
||||
$nbObjects = $this->countObjects($queryBuilder);
|
||||
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
||||
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
||||
$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'];
|
||||
$manager = $this->managerRegistry->getManagerForClass($this->objectClass);
|
||||
|
||||
for (; $offset < $nbObjects; $offset += $batchSize) {
|
||||
if ($loggerClosure) {
|
||||
|
@ -61,7 +67,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
}
|
||||
|
||||
if ($this->options['clear_object_manager']) {
|
||||
$this->managerRegistry->getManagerForClass($this->objectClass)->clear();
|
||||
$manager->clear();
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->options['disable_logging']) {
|
||||
$this->enableLogging($logger);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,6 +95,21 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -8,6 +8,40 @@ use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
|||
|
||||
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()
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
|
||||
use FOS\ElasticaBundle\Doctrine\AbstractProvider;
|
||||
use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
||||
|
||||
|
@ -10,6 +11,40 @@ class Provider extends AbstractProvider
|
|||
{
|
||||
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()
|
||||
*/
|
||||
|
|
|
@ -188,6 +188,21 @@ persistence configuration.
|
|||
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
|
||||
----------------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue