Skip to content

fix: optimize sysadmin dashboard queries and add missing indexes#165

Merged
ManukMinasyan merged 5 commits intomainfrom
fix/sysadmin-dashboard-performance
Feb 25, 2026
Merged

fix: optimize sysadmin dashboard queries and add missing indexes#165
ManukMinasyan merged 5 commits intomainfrom
fix/sysadmin-dashboard-performance

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Contributor

Summary

  • Add composite indexes (team_id, deleted_at, creation_source, created_at) to all 5 entity tables — PostgreSQL does not auto-create indexes for FK constraints, causing full table scans on 2400+ teams
  • Rewrite TopTeamsTableWidget to use EXISTS pre-filtering instead of double-computing records_count via WHERE (subquery) > 0
  • Replace SignupTrendChartWidget N+1 COUNT queries (60 queries for 30-day period) with 2 GROUP BY queries
  • Remove SQLite compatibility code (project is PostgreSQL-only)
  • Bake creation_source column and full composite index into original create migrations for future squash
  • Update copilot instructions with PostgreSQL-only and no-down() conventions
  • Add .github/skills/ to .gitignore (dotfiles symlinks)

Test plan

  • php artisan migrate — indexes created successfully
  • php artisan test --compact --filter=SystemAdmin — 28 tests pass
  • vendor/bin/phpstan analyse — 0 errors
  • vendor/bin/pint --dirty — pass
  • Manual: load sysadmin dashboard, confirm < 2s load time on production
  • Verify EXPLAIN ANALYZE shows Index Scan instead of Seq Scan on entity tables

Add composite indexes (team_id, deleted_at, creation_source, created_at)
to all entity tables — PostgreSQL does not auto-create indexes for FK
constraints. Rewrite TopTeamsTableWidget to use EXISTS pre-filtering
instead of double-computing records_count. Replace SignupTrendChartWidget
N+1 COUNT queries with 2 GROUP BY queries. Remove SQLite compatibility
code. Update copilot instructions with PostgreSQL-only and no-down()
conventions.
Copilot AI review requested due to automatic review settings February 25, 2026 13:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the sysadmin dashboard performance by addressing N+1 query issues and adding missing composite indexes to support efficient queries across 2400+ teams. The changes include database schema optimizations, query refactoring, and codebase convention updates.

Changes:

  • Added composite indexes (team_id, deleted_at, creation_source, created_at) to entity tables for PostgreSQL query optimization
  • Rewrote TopTeamsTableWidget to use EXISTS subqueries instead of computing record counts twice
  • Replaced SignupTrendChartWidget N+1 queries with efficient GROUP BY aggregations using PostgreSQL's to_char()
  • Updated migrations to remove SQLite compatibility code and prepare for future squashing
  • Documented PostgreSQL-only and no-down-method conventions in copilot instructions

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
database/migrations/2026_02_25_124942_add_team_id_indexes_to_entity_tables.php New migration adding composite indexes with idempotency checks
database/migrations/2025_04_30_143551_add_creation_source_to_entity_tables.php Simplified column addition logic, removed down method, added idempotency
database/migrations/2024_09_22_114735_create_opportunities_table.php Baked creation_source column and composite index into original migration
database/migrations/2024_09_22_091034_create_people_table.php Baked creation_source column and composite index into original migration
database/migrations/2024_09_22_084119_create_notes_table.php Baked creation_source column and composite index into original migration
database/migrations/2024_09_11_114549_create_tasks_table.php Baked creation_source column and composite index into original migration
database/migrations/2024_08_24_133803_create_companies_table.php Baked creation_source column and composite index into original migration
composer.lock Dependency updates for Laravel packages and Sentry
app-modules/SystemAdmin/src/Filament/Widgets/TopTeamsTableWidget.php Replaced double-count filter with EXISTS pre-filtering, removed SQLite compatibility
app-modules/SystemAdmin/src/Filament/Widgets/SignupTrendChartWidget.php Replaced N+1 COUNT queries with 2 GROUP BY queries using PostgreSQL to_char()
.gitignore Added .github/skills to ignore list
.github/copilot-instructions.md Documented PostgreSQL-only and no-down-method conventions

@ManukMinasyan ManukMinasyan merged commit 2620a41 into main Feb 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants