Skip to content

Commit

Permalink
Add index to liveproject_id in PopularityRecord
Browse files Browse the repository at this point in the history
- attempting to speed up queries that involve joins to PopularityRecord
  • Loading branch information
ds283 committed Mar 27, 2024
1 parent abcb388 commit 94ce34d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12349,7 +12349,7 @@ class PopularityRecord(db.Model):
id = db.Column(db.Integer(), primary_key=True)

# tag LiveProject to which this record applies
liveproject_id = db.Column(db.Integer(), db.ForeignKey("live_projects.id"))
liveproject_id = db.Column(db.Integer(), db.ForeignKey("live_projects.id"), index=True)
liveproject = db.relationship(
"LiveProject", uselist=False, backref=db.backref("popularity_data", lazy="dynamic", cascade="all, delete, delete-orphan")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Add index to liveproject_id in PopularityRecord
Revision ID: 12c4584579fb
Revises: 95dce27755c3
Create Date: 2024-03-27 15:35:47.978259
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '12c4584579fb'
down_revision = '95dce27755c3'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('popularity_record', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_popularity_record_liveproject_id'), ['liveproject_id'], unique=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('popularity_record', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_popularity_record_liveproject_id'))

# ### end Alembic commands ###

0 comments on commit 94ce34d

Please sign in to comment.