Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Symfony3 foreach causes local server to crash

I have two tables in one database that are emptied and replaced very frequently. Each table has well over 65,000 rows. I want to select two fields from the first table (LnsPriceUpdates), then take those values and compare and insert them into the second table (LnsCatalog) and want to do this for all 65,000 items in the database.

(Note: I want to do all this from a localhost)

Here's the current code I'm using:

public function testbananaAction()
{

    $em = $this->getDoctrine()->getManager();
    $query = $em
        ->createQuery(
            'SELECT l.partnumber, l.level1Net FROM AppBundle:LnsPriceUpdates l WHERE l.level1Net IS NOT NULL'
        )
        ->getResult();


    foreach ($query as $row){
        $partNo = $row['partnumber'];
        $part = $em->getRepository('AppBundle:Lnscatalog')
            ->findOneBy(['partnoid' => $partNo]);
        $dealerCost = $row['level1Net'];
        if(isset($dealerCost) && isset($part)){
            $partCheck = $part->getDealerCost();
            if(!isset($partCheck)){
                $part->setDealerCost($dealerCost);
                $em->flush();
            }
        } else {
            continue;
        }

    }
    return new Response('yay');

}

Any ideas to accomplish this task without crashing would be helpful.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Can you achieve with a single Sql Update something like:

update Lnscatalog c 
set c.dealerCost = (SELECT l.level1Net FROM AppBundle:LnsPriceUpdates l WHERE l.level1Net IS NOT NULL and l.partnumber=c.partnoid)
where c.dealerCost is null
and exists (SELECT l.level1Net FROM AppBundle:LnsPriceUpdates l WHERE l.level1Net IS NOT NULL and l.partnumber=c.partnoid)

You can speed up this query adding some index on the above table, as example:

ALTER TABLE LnsPriceUpdates 
 ADD INDEX LnsPriceUpdates_IDX_1 (level1Net, partnumber) ;

ALTER TABLE LnsPriceUpdates 
 ADD INDEX LnsPriceUpdates_IDX_2 (partnumber) ;

ALTER TABLE Lnscatalog 
 ADD INDEX Lnscatalog_IDX_2 (dealerCost) ;

Some reference about optimizing sql query can be found here, here and here

Hope this help

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda