From 2ad7dc010c8814d8d4de19e15029fa117d0ee233 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 17 Jan 2025 17:09:10 +0100 Subject: [PATCH] perf(tf): index by the test run group ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on the Sentry's backend insights, it appears that in the last 90d we have spent 16.82min running the query that filters out rows based on the «test run group id», therefore index that column to improve the speed of the queries done. Signed-off-by: Matej Focko --- ...3cfec8ce0f7_index_tft_test_run_group_id.py | 30 +++++++++++++++++++ packit_service/models.py | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/e3cfec8ce0f7_index_tft_test_run_group_id.py diff --git a/alembic/versions/e3cfec8ce0f7_index_tft_test_run_group_id.py b/alembic/versions/e3cfec8ce0f7_index_tft_test_run_group_id.py new file mode 100644 index 000000000..dc9c516be --- /dev/null +++ b/alembic/versions/e3cfec8ce0f7_index_tft_test_run_group_id.py @@ -0,0 +1,30 @@ +"""Index tft_test_run_group_id + +Revision ID: e3cfec8ce0f7 +Revises: d625d6c1122f +Create Date: 2025-01-17 16:06:29.833622 + +""" + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "e3cfec8ce0f7" +down_revision = "d625d6c1122f" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_index( + op.f("ix_tft_test_run_targets_tft_test_run_group_id"), + "tft_test_run_targets", + ["tft_test_run_group_id"], + unique=False, + ) + + +def downgrade(): + op.drop_index( + op.f("ix_tft_test_run_targets_tft_test_run_group_id"), table_name="tft_test_run_targets" + ) diff --git a/packit_service/models.py b/packit_service/models.py index aa91d2768..5228c2799 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -3325,7 +3325,7 @@ class TFTTestRunTargetModel(GroupAndTargetModelConnector, Base): # so it will run when the model is initiated, not when the table is made submitted_time = Column(DateTime, default=datetime.utcnow) data = Column(JSON) - tft_test_run_group_id = Column(Integer, ForeignKey("tft_test_run_groups.id")) + tft_test_run_group_id = Column(Integer, ForeignKey("tft_test_run_groups.id"), index=True) copr_builds = relationship( "CoprBuildTargetModel",