Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Symfony3 foreach hace que el servidor local se bloquee

Tengo dos tablas en una base de datos que se vacían y reemplazan con mucha frecuencia. Cada tabla tiene más de 65.000 filas. Quiero seleccionar dos campos de la primera tabla ( LnsPriceUpdates ), luego tomar esos valores y compararlos e insertarlos en la segunda tabla ( LnsCatalog ) y quiero hacer esto para los 65 000 elementos de la base de datos.

(Nota: quiero hacer todo esto desde un host local)

Aquí está el código actual que estoy usando:

 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'); }

Cualquier idea para realizar esta tarea sin fallar sería útil.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¿Puedes lograr con una sola actualización Sql algo como:

 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)

Puede acelerar esta consulta agregando algún índice en la tabla anterior, como ejemplo:

 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) ;

Se pueden encontrar algunas referencias sobre la optimización de consultas SQL aquí , aquí y aquí

Espero que esto ayude

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!