Find and optimise slow SQL queries in an existing ORM layer
Cursor reads the SQLAlchemy model definitions and the slow-query log, identifies N+1 patterns and missing indexes, rewrites the problematic queries using eager loading, and generates the Alembic migration to add the indexes.
Dashboard load time drops from 4.2 s to 0.6 s; the migration is production-ready with rollback included.
Open Cursor chat with the ORM files in context: "Here is the slow-query log. Find N+1 patterns and missing indexes in models/. Rewrite the queries and generate an Alembic migration for the recommended indexes."