Reputation: 158
We're having problems with creating a small entity using Symfony2 and Doctrine, it works but it's very slow and memory exhausting.
We believe that the problem lies within Symfony's $form->submit()
.
This takes ~0.1 seconds:
die('x');
$form->submit($request);
This takes ~60 seconds:
$form->submit($request);
die('x');
We have tried to "die()" inside this submit method, all the way down to return $this;
and the run time is roughly 0.1 seconds. It seems like something else is happening behind the scenes and we can't locate the problem.
Running XDebug tells us the following: Symfony\Component\Form\Form->submit has the highest inclusive cost and mainly this call: Symfony\Component\Form\Form->viewToNorm.
We have tried the following:
No difference in dev or prod environment.
Upvotes: 0
Views: 651
Reputation: 158
We solved it by adding query_builder to our form builder and now everything works fine again.
From:
->add('authentication', 'entity', array(
'class' => 'Model\Authentication',
'required' => false,
'multiple' => false,
'property' => 'id',
'invalid_message' => _('No authentication entity found')
))
to:
->add('authentication', 'entity', array(
'class' => 'Model\Authentication',
'required' => false,
'multiple' => false,
'property' => 'id',
'invalid_message' => _('No authentication entity found'),
'query_builder' => function (EntityRepository $er) {
return $er
->createQueryBuilder('au')
->select('au')
;
}
))
Upvotes: 1