php - symfony 3 iteration of array of objects too long -


i got array of symfony3 entities 50000 in total. need iterate array , find entities match criteria. code shown below:

$p_r = $em->getrepository('appbundle:product_region')->findall();//50000 elements in array $rowid_2 = $product->getrowid();//some product entity  foreach($p_r $pr){    $rowid_1 = $pr->getproductid()->getrowid();     if($rowid_1 == $rowid_2){      $regions[] = $pr->getregionid()->getname();      $filial_name = $pr->getregionid()->getfilial()->getname();       if(!in_array($filial_name, $filials)){        $filials[] =  $filial_name;       }    } } 

the problem when iteration takes approx 1 second long.it takes 25% of cpu 1 core finish operation. tested on different array of numbers , observed took 0.002 sec iterate through 50 000 elements. ideas how speed , search delay welcome. thank you.

if want find entities match criteria use doctrine's 2 criteria fetch entities.

i found usefull. here have link doctrine's docs:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections

hope helps. :)


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -