Created
January 24, 2012 13:23
-
-
Save yuriteixeira/1670161 to your computer and use it in GitHub Desktop.
Should execute multiple inserts (400 queries with 100 rows each, but executing regular 4000 queries instead)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Route("/sandbox/insert-test") | |
* @Template() | |
*/ | |
public function insertTestAction() { | |
$em = $this->getDoctrine()->getEntityManager(); | |
$datetime = new \DateTime(); | |
$qtty = 4000; | |
$batchSize = 100; | |
for ($i = 0; $i < $qtty; $i++) { | |
$country = new Country(); | |
$country->setName(uniqid()); | |
$country->setCreated($datetime); | |
$country->setModified($datetime); | |
$em->persist($country); | |
if ($i % $batchSize == 0 || $i == ($qtty - 1)) { | |
$em->flush(); | |
$em->clear(); | |
} | |
} | |
return array(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment