From 22a0a52f7bb7798838660a8548f4f219013929f6 Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> Date: Thu, 17 Apr 2025 00:04:58 +0200 Subject: [PATCH] Chunk `Sushi` inserts based on rows count (#1259) --- app/Models/File.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Models/File.php b/app/Models/File.php index 80077f63e..b2ceaed5c 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -33,6 +33,8 @@ class File extends Model protected $keyType = 'string'; + protected int $sushiInsertChunkSize = 100; + public const ARCHIVE_MIMES = [ 'application/vnd.rar', // .rar 'application/x-rar-compressed', // .rar (2) @@ -167,7 +169,7 @@ class File extends Model throw new Exception($contents['error']); } - return array_map(function ($file) { + $rows = array_map(function ($file) { return [ 'name' => $file['name'], 'created_at' => Carbon::parse($file['created'])->timezone('UTC'), @@ -181,6 +183,10 @@ class File extends Model 'mime_type' => $file['mime'], ]; }, $contents); + + $this->sushiInsertChunkSize = min((int) floor(999 / count($this->getSchema())), count($rows)); + + return $rows; } catch (Exception $exception) { report($exception);