started to add indexes and fixed N+1 issue

This commit is contained in:
Mark Gregory
2026-06-12 13:52:45 +01:00
parent 8ec2c33c47
commit 4dcee08d71
7 changed files with 136 additions and 25 deletions
@@ -0,0 +1,65 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class HelpdeskPerformanceIndexes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('helpdesk_tickets', function (Blueprint $table): void {
$table->index(['company_id', 'status_id']);
$table->index(['company_id', 'priority_id']);
$table->index(['company_id', 'category_id']);
$table->index(['company_id', 'project_id']);
$table->index(['company_id', 'team_id']);
$table->index(['agent_id', 'completed_at']);
$table->index(['user_id', 'created_at']);
$table->index(['status_id', 'created_at']);
$table->index(['last_activity_at']);
$table->index(['due_at']);
$table->index(['reference']);
});
Schema::table('helpdesk_comments', function (Blueprint $table): void {
$table->index(['ticket_id', 'parent_id']);
$table->index(['ticket_id', 'created_at']);
$table->index(['parent_id', 'created_at']);
$table->index(['user_id', 'created_at']);
});
Schema::table('helpdesk_attachments', function (Blueprint $table): void {
$table->index(['ticket_id']);
$table->index(['comment_id']);
$table->index(['user_id']);
});
Schema::table('helpdesk_projects', function (Blueprint $table): void {
$table->index(['company_id', 'archived_at']);
});
Schema::table('helpdesk_teams', function (Blueprint $table): void {
$table->index(['company_id', 'archived_at']);
});
Schema::table('helpdesk_category_user', function (Blueprint $table): void {
$table->index(['category_id', 'user_id']);
$table->index(['user_id', 'category_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}