Skip to content

Commit

Permalink
refactor: chunk insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Mar 23, 2021
1 parent 9391f23 commit 0595e53
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Concerns/Orbital.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Orbit\Facades\Orbit;
use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Schema;
use Orbit\Events\OrbitalCreated;
use Orbit\Events\OrbitalDeleted;
Expand Down Expand Up @@ -125,20 +126,19 @@ public function migrate()
$driver = Orbit::driver(static::getOrbitalDriver());
$columns = $schema->getColumnListing($table);

$driver->all(static::getOrbitalPath())->each(function ($row) use ($columns) {
$row = collect($row)
->filter(function ($_, $key) use ($columns) {
return in_array($key, $columns);
})
->map(function ($value, $key) {
$this->setAttribute($key, $value);

return $this->attributes[$key];
})
->toArray();

static::insert($row);
});
$driver->all(static::getOrbitalPath())
->map(function ($row) use ($columns) {
return collect($row)
->filter(fn ($_, $key) => in_array($key, $columns))
->map(function ($value, $key) {
$this->setAttribute($key, $value);

return $this->attributes[$key];
})
->toArray();
})
->chunk(100)
->each(fn (Collection $chunk) => static::insert($chunk->toArray()));
}

protected static function getOrbitalDriver()
Expand Down

0 comments on commit 0595e53

Please sign in to comment.