From 98b4afa4f2fb152349f93aa1299093e980d5709e Mon Sep 17 00:00:00 2001 From: Caio Fonseca Date: Mon, 28 Sep 2026 23:12:07 +0100 Subject: [PATCH] fix: add repository activity indexes for issues and pull requests Signed-off-by: Caio Fonseca --- collectoss/application/db/models/data.py | 4 ++ .../45_add_issue_pr_activity_indexes.py | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 collectoss/application/schema/alembic/versions/45_add_issue_pr_activity_indexes.py diff --git a/collectoss/application/db/models/data.py b/collectoss/application/db/models/data.py index aa4d30482..66d654d8e 100644 --- a/collectoss/application/db/models/data.py +++ b/collectoss/application/db/models/data.py @@ -1439,6 +1439,8 @@ class Issue(Base): Index("issues_ibfk_1", "repo_id"), Index("issues_ibfk_2", "reporter_id"), Index("issues_ibfk_4", "pull_request_id"), + Index("issues_idx_repo_id_updated_at", "repo_id", "updated_at"), + Index("issues_idx_repo_id_created_at", "repo_id", "created_at"), UniqueConstraint("repo_id", "gh_issue_id"), UniqueConstraint("issue_url", name="issue-insert-unique"), @@ -1747,6 +1749,8 @@ class PullRequest(Base): Index( "pull_requests_idx_repo_id_data_datex", "repo_id", "data_collection_date" ), + Index("pull_requests_idx_repo_id_pr_updated_at", "repo_id", "pr_updated_at"), + Index("pull_requests_idx_repo_id_pr_created_at", "repo_id", "pr_created_at"), Index("pr_ID_prs_table", "pull_request_id"), {"schema": "data"}, ) diff --git a/collectoss/application/schema/alembic/versions/45_add_issue_pr_activity_indexes.py b/collectoss/application/schema/alembic/versions/45_add_issue_pr_activity_indexes.py new file mode 100644 index 000000000..eb791df2b --- /dev/null +++ b/collectoss/application/schema/alembic/versions/45_add_issue_pr_activity_indexes.py @@ -0,0 +1,56 @@ +"""add issue and pull request activity indexes + +Revision ID: 45 +Revises: 44 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = '45' +down_revision = '44' +branch_labels = None +depends_on = None + + +def upgrade(): + # Concurrent builds keep these tables writable during collection. + with op.get_context().autocommit_block(): + op.create_index( + 'issues_idx_repo_id_updated_at', 'issues', ['repo_id', 'updated_at'], + schema='data', postgresql_concurrently=True, + ) + op.create_index( + 'issues_idx_repo_id_created_at', 'issues', ['repo_id', 'created_at'], + schema='data', postgresql_concurrently=True, + ) + op.create_index( + 'pull_requests_idx_repo_id_pr_updated_at', 'pull_requests', + ['repo_id', 'pr_updated_at'], + schema='data', postgresql_concurrently=True, + ) + op.create_index( + 'pull_requests_idx_repo_id_pr_created_at', 'pull_requests', + ['repo_id', 'pr_created_at'], + schema='data', postgresql_concurrently=True, + ) + + +def downgrade(): + with op.get_context().autocommit_block(): + op.drop_index( + 'pull_requests_idx_repo_id_pr_created_at', table_name='pull_requests', + schema='data', postgresql_concurrently=True, + ) + op.drop_index( + 'pull_requests_idx_repo_id_pr_updated_at', table_name='pull_requests', + schema='data', postgresql_concurrently=True, + ) + op.drop_index( + 'issues_idx_repo_id_created_at', table_name='issues', + schema='data', postgresql_concurrently=True, + ) + op.drop_index( + 'issues_idx_repo_id_updated_at', table_name='issues', + schema='data', postgresql_concurrently=True, + )