Bulk update. Still working on bulk delete for indexes and types in Elastica.
This commit is contained in:
parent
4a4716a55b
commit
b6d010a9d7
|
@ -214,13 +214,9 @@ class Listener implements EventSubscriber
|
|||
*/
|
||||
private function persistScheduled()
|
||||
{
|
||||
if (count($this->scheduledForInsertion)) {
|
||||
$this->objectPersister->insertMany($this->scheduledForInsertion);
|
||||
}
|
||||
$this->objectPersister->bulkPersist($this->scheduledForInsertion, ObjectPersisterInterface::BULK_INSERT);
|
||||
$this->objectPersister->bulkPersist($this->scheduledForUpdate, ObjectPersisterInterface::BULK_REPLACE);
|
||||
|
||||
foreach ($this->scheduledForUpdate as $entity) {
|
||||
$this->objectPersister->replaceOne($entity);
|
||||
}
|
||||
foreach ($this->scheduledForDeletion as $entity) {
|
||||
$this->objectPersister->deleteOne($entity);
|
||||
}
|
||||
|
|
|
@ -83,19 +83,24 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
} catch (NotFoundException $e) {}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inserts an array of objects in the type
|
||||
* Bulk update an array of objects in the type for the given method
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
**/
|
||||
public function insertMany(array $objects)
|
||||
* @param string Method to call
|
||||
*/
|
||||
public function bulkPersist(array $objects, $method)
|
||||
{
|
||||
if (!count($objects)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$documents = array();
|
||||
foreach ($objects as $object) {
|
||||
$documents[] = $this->transformToElasticaDocument($object);
|
||||
}
|
||||
$this->type->addDocuments($documents);
|
||||
|
||||
$this->type->$method($documents);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,4 +113,4 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
{
|
||||
return $this->transformer->transform($object, $this->fields);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,9 @@ namespace FOS\ElasticaBundle\Persister;
|
|||
*/
|
||||
interface ObjectPersisterInterface
|
||||
{
|
||||
const BULK_INSERT = 'addDocuments';
|
||||
const BULK_REPLACE = 'updateDocuments';
|
||||
|
||||
/**
|
||||
* Insert one object into the type
|
||||
* The object will be transformed to an elastica document
|
||||
|
@ -42,9 +45,10 @@ interface ObjectPersisterInterface
|
|||
function deleteById($id);
|
||||
|
||||
/**
|
||||
* Inserts an array of objects in the type
|
||||
* Bulk update an array of objects in the type for the given method
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
**/
|
||||
function insertMany(array $objects);
|
||||
* @param string Method to call
|
||||
*/
|
||||
function bulkPersist(array $objects, $method);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue