fix: don't queue market data seed
This commit is contained in:
@@ -12,8 +12,6 @@ class MarketDataSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
use WithoutModelEvents;
|
use WithoutModelEvents;
|
||||||
|
|
||||||
public array $rows = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*/
|
*/
|
||||||
@@ -44,7 +42,7 @@ class MarketDataSeeder extends Seeder
|
|||||||
$meta_data = json_decode(base64_decode($data['meta_data']), true);
|
$meta_data = json_decode(base64_decode($data['meta_data']), true);
|
||||||
$meta_data['source'] = 'market_data_seeder';
|
$meta_data['source'] = 'market_data_seeder';
|
||||||
|
|
||||||
$this->rows[] = [
|
$rows[] = [
|
||||||
'symbol' => $data['symbol'],
|
'symbol' => $data['symbol'],
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'currency' => $data['currency'],
|
'currency' => $data['currency'],
|
||||||
@@ -54,15 +52,17 @@ class MarketDataSeeder extends Seeder
|
|||||||
$rowCount++;
|
$rowCount++;
|
||||||
|
|
||||||
if ($rowCount % $chunkSize == 0) {
|
if ($rowCount % $chunkSize == 0) {
|
||||||
$this->bulkInsert($this->rows);
|
$this->bulkInsert($rows);
|
||||||
|
$rows = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// final clean up
|
// final clean up
|
||||||
if (! empty($this->rows)) {
|
if (! empty($rows)) {
|
||||||
|
|
||||||
$this->bulkInsert($this->rows);
|
$this->bulkInsert($rows);
|
||||||
|
$rows = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the CSV file
|
// Close the CSV file
|
||||||
@@ -76,19 +76,17 @@ class MarketDataSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bulkInsert($rows)
|
private function bulkInsert($rows): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
dispatch(
|
DB::table('market_data')->upsert($rows, ['symbol'], ['name', 'currency', 'meta_data']);
|
||||||
fn () => DB::table('market_data')->upsert($rows, ['symbol'], ['name', 'currency', 'meta_data'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->rows = [];
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|
||||||
throw new \Exception('Error: '.$e->getMessage());
|
throw new \Exception('Error: '.$e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gc_collect_cycles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ class MarketDataTest extends TestCase
|
|||||||
'--force' => true,
|
'--force' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(14262, MarketData::count('symbol'));
|
$this->assertEquals(13186, MarketData::count('symbol'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_can_get_quote_from_provider()
|
public function test_can_get_quote_from_provider()
|
||||||
|
|||||||
Reference in New Issue
Block a user