diff --git a/lib/Command/PlacesSetup.php b/lib/Command/PlacesSetup.php index 5fbebce9..c716a2d0 100644 --- a/lib/Command/PlacesSetup.php +++ b/lib/Command/PlacesSetup.php @@ -168,6 +168,9 @@ class PlacesSetup extends Command $sql = str_replace('*PREFIX*memories_planet_geometry', 'memories_planet_geometry', $query->getSQL()); $insertGeometry = $this->connection->prepare($sql); + // The number of places in the current transaction + $txnCount = 0; + // Iterate over the data file $handle = fopen($datafile, 'r'); if ($handle) { @@ -177,6 +180,11 @@ class PlacesSetup extends Command if ('' === trim($line)) { continue; } + + // Begin transaction + if (0 === $txnCount++) { + $this->connection->beginTransaction(); + } ++$count; // Decode JSON @@ -260,10 +268,14 @@ class PlacesSetup extends Command } } - // Print progress - if (0 === $count % 500) { + // Commit transaction every once in a while + if ($count % 250 === 0) { + $this->connection->commit(); + $txnCount = 0; + + // Print progress $end = time(); - $elapsed = $end - $start; + $elapsed = ($end - $start) ?: 1; $rate = $count / $elapsed; $remaining = APPROX_PLACES - $count; $eta = round($remaining / $rate); @@ -275,6 +287,11 @@ class PlacesSetup extends Command fclose($handle); } + // Commit final transaction + if ($txnCount > 0) { + $this->connection->commit(); + } + // Delete file unlink($datafile);