Attempt to fix N+1 issues

This commit is contained in:
Mark Gregory
2026-06-16 20:05:13 +01:00
parent fc3371ea77
commit 85b96144c0
3 changed files with 14 additions and 4 deletions
+6 -3
View File
@@ -55,6 +55,9 @@ final class TicketShow extends Component
public function mount(Ticket $ticket): void
{
Auth::user()?->loadMissing('company');
$ticket->loadMissing(['owner.company', 'agent.company']);
$this->authorize('view', $ticket);
$this->ticket = $this->freshTicket($ticket);
$this->status_id = $this->ticket->status_id;
@@ -295,13 +298,13 @@ final class TicketShow extends Component
'ratings',
'tags',
'checklistItems',
'attachments.user',
'attachments.user.company',
'gitCommits.repository',
]) ?? $ticket;
$comments = \Modules\Helpdesk\Models\Comment::query()
->where('ticket_id', $ticket->id)
->with(['user', 'attachments.user'])
->with(['user.company', 'attachments.user.company'])
->oldest()
->get();
@@ -326,7 +329,7 @@ final class TicketShow extends Component
$columns[] = 'company_id';
}
$query = User::query()->select($columns)->orderBy('name');
$query = User::query()->select($columns)->with('company')->orderBy('name');
if ($this->ticket->company_id !== null && Schema::hasColumn('users', 'company_id')) {
$tenantUsers = (clone $query)
+7
View File
@@ -197,3 +197,10 @@ versions:
- Eager-loaded requester and agent company relations on the ticket detail/edit views to prevent Debugbar N+1 alerts.
- Kept agent, status and priority persistence on CSRF-protected POST routes with compact action buttons.
- Kept module.json version in sync with changelog.yaml.
"1.3.11":
changed:
- Eager-loaded the current user company, ticket requester company, ticket agent company, comment user company and attachment user company on the ticket detail page to remove the remaining Debugbar N+1 alert.
- Eager-loaded company data for assignable agent dropdown users without changing agent, status or priority persistence behaviour.
- Kept module.json version in sync with changelog.yaml.
+1 -1
View File
@@ -22,5 +22,5 @@
"Modules\\Helpdesk\\Providers\\HelpdeskServiceProvider"
],
"files": [],
"version": "1.3.10"
"version": "1.3.11"
}