From 10b8a8c95c54362914206ac575450cbedf49c67c Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Mon, 1 Sep 2025 17:40:28 +0800 Subject: [PATCH] =?UTF-8?q?202509011736=20Bug=20=E5=90=8C=E6=AD=A5TextAd?= =?UTF-8?q?=20=E6=9C=83=E9=8C=AF=20=EF=BC=8CSqlite=E7=AD=86=E6=95=B8?= =?UTF-8?q?=E9=99=90=E5=88=B6=20=E5=9C=A8999?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/ExportSqliteTextAdJob.php | 3 +++ app/Jobs/SendSqliteFileJob.php | 2 +- app/Services/SqliteExportService.php | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Jobs/ExportSqliteTextAdJob.php b/app/Jobs/ExportSqliteTextAdJob.php index 68fff43..a3081e3 100644 --- a/app/Jobs/ExportSqliteTextAdJob.php +++ b/app/Jobs/ExportSqliteTextAdJob.php @@ -9,6 +9,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; class ExportSqliteTextAdJob implements ShouldQueue { diff --git a/app/Jobs/SendSqliteFileJob.php b/app/Jobs/SendSqliteFileJob.php index 9f07e38..52bb998 100644 --- a/app/Jobs/SendSqliteFileJob.php +++ b/app/Jobs/SendSqliteFileJob.php @@ -32,7 +32,7 @@ class SendSqliteFileJob implements ShouldQueue Log::error("❌ SQLite 檔案不存在: {$path}"); return; } - $user = \App\Models\User::find(2); + $user = \App\Models\User::find(1); $token = $user->api_plain_token; $branches = $this->branchId diff --git a/app/Services/SqliteExportService.php b/app/Services/SqliteExportService.php index 9bbb032..ddab4a9 100644 --- a/app/Services/SqliteExportService.php +++ b/app/Services/SqliteExportService.php @@ -96,7 +96,12 @@ class SqliteExportService protected function insertData(string $table, array $rows): void { if (empty($rows)) return; - DB::connection($this->connection)->table($table)->insert($rows); + $columns = count($rows[0]); + $maxBatch = intdiv(999, $columns); + + foreach (array_chunk($rows, $maxBatch) as $chunk) { + DB::connection($this->connection)->table($table)->insert($chunk); + } } protected function purge(): void