From be1742a85c52601a14707750f6d816a6bf3d9cb1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 13 Feb 2025 09:55:24 +0100 Subject: [PATCH] fix(s3-storage): optimize team admin notification query --- app/Models/S3Storage.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Models/S3Storage.php b/app/Models/S3Storage.php index 33f4fa37c..5a9eb87a3 100644 --- a/app/Models/S3Storage.php +++ b/app/Models/S3Storage.php @@ -53,13 +53,14 @@ class S3Storage extends BaseModel $mail = new MailMessage; $mail->subject('Coolify: S3 Storage Connection Error'); $mail->view('emails.s3-connection-error', ['name' => $this->name, 'reason' => $e->getMessage(), 'url' => route('storage.show', ['storage_uuid' => $this->uuid])]); - $users = collect([]); - $members = $this->team->members()->get(); - foreach ($members as $user) { - if ($user->isAdmin()) { - $users->push($user); - } - } + + // Load the team with its members and their roles explicitly + $team = $this->team()->with(['members' => function ($query) { + $query->withPivot('role'); + }])->first(); + + // Get admins directly from the pivot relationship for this specific team + $users = $team->members()->wherePivotIn('role', ['admin', 'owner'])->get(['users.id', 'users.email']); foreach ($users as $user) { send_user_an_email($mail, $user->email); }