From 9e6b6e7b82f6ce4a2a1532b2152d7fef43136006 Mon Sep 17 00:00:00 2001 From: takatost Date: Tue, 28 May 2024 20:41:52 +0800 Subject: [PATCH] fix: workflow run sequence number slow sql (#4737) --- .../64a70a7aab8b_add_workflow_run_index.py | 32 +++++++++++++++++++ api/models/workflow.py | 1 + 2 files changed, 33 insertions(+) create mode 100644 api/migrations/versions/64a70a7aab8b_add_workflow_run_index.py diff --git a/api/migrations/versions/64a70a7aab8b_add_workflow_run_index.py b/api/migrations/versions/64a70a7aab8b_add_workflow_run_index.py new file mode 100644 index 0000000000..73242908f4 --- /dev/null +++ b/api/migrations/versions/64a70a7aab8b_add_workflow_run_index.py @@ -0,0 +1,32 @@ +"""add workflow run index + +Revision ID: 64a70a7aab8b +Revises: 03f98355ba0e +Create Date: 2024-05-28 12:32:00.276061 + +""" +from alembic import op + +import models as models + +# revision identifiers, used by Alembic. +revision = '64a70a7aab8b' +down_revision = '03f98355ba0e' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('workflow_runs', schema=None) as batch_op: + batch_op.create_index('workflow_run_tenant_app_sequence_idx', ['tenant_id', 'app_id', 'sequence_number'], unique=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('workflow_runs', schema=None) as batch_op: + batch_op.drop_index('workflow_run_tenant_app_sequence_idx') + + # ### end Alembic commands ### diff --git a/api/models/workflow.py b/api/models/workflow.py index 264fea4ecb..d9bc784878 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -263,6 +263,7 @@ class WorkflowRun(db.Model): __table_args__ = ( db.PrimaryKeyConstraint('id', name='workflow_run_pkey'), db.Index('workflow_run_triggerd_from_idx', 'tenant_id', 'app_id', 'triggered_from'), + db.Index('workflow_run_tenant_app_sequence_idx', 'tenant_id', 'app_id', 'sequence_number'), ) id = db.Column(StringUUID, server_default=db.text('uuid_generate_v4()'))