Skip to content

Commit

Permalink
Fix chunking (#30)
Browse files Browse the repository at this point in the history
* chore: ignore vendor files and composer.lock

* chore: fix insert chunking

The code was inserting a row at a time after the first chunk making the process slow.

With this fix, rows are inserted every time the parsed data array has enough records, not just the first time.
  • Loading branch information
Xint0-elab authored Sep 18, 2023
1 parent c97d191 commit 8c3aa44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/
composer.lock
vendor
4 changes: 1 addition & 3 deletions src/CsvSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private function parseCSV()

$this->count ++;

if( $this->count >= $this->chunk ) $this->insertRows();
if( count($this->parsedData) >= $this->chunk ) $this->insertRows();
}

$this->insertRows();
Expand All @@ -437,8 +437,6 @@ private function insertRows()
DB::connection($this->connection)->table( $this->tablename )->insert( $this->parsedData );

$this->parsedData = [];

$this->chunk ++;
}
catch (\Exception $e)
{
Expand Down

0 comments on commit 8c3aa44

Please sign in to comment.