From d5f47623417ef34f0ab53621f32e179513e97ab0 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Thu, 12 Feb 2026 07:55:17 +0000 Subject: [PATCH] backend: add composite task listing indexes --- ..._add_composite_indexes_for_task_listing.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 backend/migrations/versions/b4338be78eec_add_composite_indexes_for_task_listing.py diff --git a/backend/migrations/versions/b4338be78eec_add_composite_indexes_for_task_listing.py b/backend/migrations/versions/b4338be78eec_add_composite_indexes_for_task_listing.py new file mode 100644 index 00000000..010128a3 --- /dev/null +++ b/backend/migrations/versions/b4338be78eec_add_composite_indexes_for_task_listing.py @@ -0,0 +1,45 @@ +"""add composite indexes for task listing + +Revision ID: b4338be78eec +Revises: f4d2b649e93a +Create Date: 2026-02-12 07:54:27.450391 + +""" +from __future__ import annotations + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b4338be78eec' +down_revision = 'f4d2b649e93a' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # Task list endpoints filter primarily by board_id, optionally by status + # and assigned_agent_id, and always order by created_at (desc in code). + # These composite btree indexes allow fast backward scans with LIMIT. + op.create_index( + "ix_tasks_board_id_created_at", + "tasks", + ["board_id", "created_at"], + ) + op.create_index( + "ix_tasks_board_id_status_created_at", + "tasks", + ["board_id", "status", "created_at"], + ) + op.create_index( + "ix_tasks_board_id_assigned_agent_id_created_at", + "tasks", + ["board_id", "assigned_agent_id", "created_at"], + ) + + +def downgrade() -> None: + op.drop_index("ix_tasks_board_id_assigned_agent_id_created_at", table_name="tasks") + op.drop_index("ix_tasks_board_id_status_created_at", table_name="tasks") + op.drop_index("ix_tasks_board_id_created_at", table_name="tasks")