Skip to content

Instantly share code, notes, and snippets.

@yuriteixeira
Created January 24, 2012 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriteixeira/1670161 to your computer and use it in GitHub Desktop.
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)
/**
* @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