Browse Source

Add fix to improve speed see BT#11586

jmontoyaa 8 years ago
parent
commit
0cdcbc70f9
1 changed files with 13 additions and 0 deletions
  1. 13 0
      main/cron/import_csv.php

+ 13 - 0
main/cron/import_csv.php

@@ -769,6 +769,7 @@ class ImportCsv
             $this->logger->addInfo(count($data)." records found.");
             $eventsToCreate = array();
             $errorFound = false;
+
             foreach ($data as $row) {
                 $sessionId = null;
                 $externalSessionId = null;
@@ -906,6 +907,10 @@ class ImportCsv
                 return 0;
             }
 
+            $batchSize = $this->batchSize;
+            $counter = 1;
+            $em = Database::getManager();
+
             foreach ($eventsToCreate as $event) {
                 $update = false;
                 $item = null;
@@ -1034,7 +1039,15 @@ class ImportCsv
                         );
                     }
                 }
+
+                if (($counter % $batchSize) === 0) {
+                    $em->flush();
+                    $em->clear(); // Detaches all objects from Doctrine!
+                }
+                $counter++;
             }
+
+            $em->clear(); // Detaches all objects from Doctrine!
         }
 
         if ($moveFile) {