Skip to content

Commit

Permalink
Add index to FileDownload table on data obj id
Browse files Browse the repository at this point in the history
  • Loading branch information
naglepuff committed Feb 28, 2025
1 parent 4c562c1 commit 46c7e9d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Add an index on `data_object_id` column of `file_download` table
Speed up computing download counts for data objecsts.
Revision ID: c27777e272d3
Revises: 6e6dec0daa7c
Create Date: 2025-02-28 20:38:34.018502
"""

from typing import Optional

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "c27777e272d3"
down_revision: Optional[str] = "6e6dec0daa7c"
branch_labels: Optional[str] = None
depends_on: Optional[str] = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(
op.f("ix_file_download_data_object_id"), "file_download", ["data_object_id"], unique=False
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_file_download_data_object_id"), table_name="file_download")
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion nmdc_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ class FileDownload(Base):

id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
created = Column(DateTime, nullable=False, default=datetime.utcnow)
data_object_id = Column(String, ForeignKey("data_object.id"), nullable=False)
data_object_id = Column(String, ForeignKey("data_object.id"), nullable=False, index=True)
ip = Column(String, nullable=False)
user_agent = Column(String, nullable=True)
orcid = Column(String, nullable=False)
Expand Down

0 comments on commit 46c7e9d

Please sign in to comment.