Limit the flush action

Calling flush is a resource intensive operation, especially when a lot of entities are managed by Doctrine. You should pass the entity you want to flush as parameter, or avoid flushing inside a loop.