Skip to content

Commit

Permalink
fix(s3-storage): optimize team admin notification query
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Feb 13, 2025
1 parent 3c538e0 commit be1742a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/Models/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ public function testConnection(bool $shouldSave = false)
$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);
}
Expand Down

0 comments on commit be1742a

Please sign in to comment.