Attempt to fix N+1 issues

This commit is contained in:
Mark Gregory
2026-06-16 20:09:21 +01:00
parent 85b96144c0
commit e81a509007
6 changed files with 67 additions and 22 deletions
+16 -5
View File
@@ -55,8 +55,7 @@ final class TicketShow extends Component
public function mount(Ticket $ticket): void
{
Auth::user()?->loadMissing('company');
$ticket->loadMissing(['owner.company', 'agent.company']);
$ticket->loadMissing($this->ticketDetailRelations());
$this->authorize('view', $ticket);
$this->ticket = $this->freshTicket($ticket);
@@ -262,6 +261,8 @@ final class TicketShow extends Component
public function render(): View
{
$this->ticket = $this->freshTicket($this->ticket);
return view('helpdesk::livewire.ticket-show', [
'statuses' => Status::query()->orderBy('sort_order')->get(),
'priorities' => Priority::query()->orderBy('sort_order')->get(),
@@ -282,9 +283,14 @@ final class TicketShow extends Component
return (int) $value;
}
private function freshTicket(Ticket $ticket): Ticket
/**
* Relations required by the ticket detail view and workflow renderers.
*
* @return list<string>
*/
private function ticketDetailRelations(): array
{
$ticket = $ticket->fresh([
return [
'owner.company',
'agent.company',
'status',
@@ -300,7 +306,12 @@ final class TicketShow extends Component
'checklistItems',
'attachments.user.company',
'gitCommits.repository',
]) ?? $ticket;
];
}
private function freshTicket(Ticket $ticket): Ticket
{
$ticket = $ticket->fresh($this->ticketDetailRelations()) ?? $ticket;
$comments = \Modules\Helpdesk\Models\Comment::query()
->where('ticket_id', $ticket->id)