From 4471b5e50979c3ad891f08bd2aee8e89a290f5e0 Mon Sep 17 00:00:00 2001 From: paoloGuagnano Date: Fri, 23 Feb 2024 19:02:29 +0100 Subject: [PATCH] add metod upsert and insert record in unique request --- app/Jobs/ImportCSVFileJob.php | 21 ++++++++++++++------- config/queue.php | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Jobs/ImportCSVFileJob.php b/app/Jobs/ImportCSVFileJob.php index dbb809e..5cfe344 100644 --- a/app/Jobs/ImportCSVFileJob.php +++ b/app/Jobs/ImportCSVFileJob.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use App\Models\Word; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; class ImportCSVFileJob implements ShouldQueue @@ -34,19 +35,25 @@ class ImportCSVFileJob implements ShouldQueue ]; $fileStream = fopen($this->filepath, 'r'); $skipHeader = true; + $finalarray = array(); while ($row = fgetcsv($fileStream)) { if ($skipHeader) { $skipHeader = false; continue; } - Word::updateOrCreate( - [ - 'name' => $row[$mapping['name']], - 'translation' => $row[$mapping['translation']], - ] + $finalarray[] = array( + 'name' => $row[$mapping['name']], + 'translation' => $row[$mapping['translation']], ); + //Word::updateOrCreate( + // [ + // 'name' => $row[$mapping['name']], + // 'translation' => $row[$mapping['translation']], + // ] + //); } - fclose($fileStream); - Storage::delete($this->filepath); + DB::table('words')->upsert($finalarray, 'name', 'translation'); + //fclose($fileStream); + //Storage::delete($this->filepath); } } diff --git a/config/queue.php b/config/queue.php index 84eebcd..3e2f381 100644 --- a/config/queue.php +++ b/config/queue.php @@ -38,7 +38,7 @@ return [ 'driver' => 'database', 'table' => 'jobs', 'queue' => 'default', - 'retry_after' => 1250, + 'retry_after' => 9000, 'after_commit' => false, ],