From d5ae01b45697bcd2e2f95a98cadb4bd1fecca19e Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 15 Nov 2024 16:42:08 +1300 Subject: [PATCH] add index #348 --- app/models.py | 4 +- .../d32ef1893ce4_index_on_vote_author_id.py | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 migrations/versions/d32ef1893ce4_index_on_vote_author_id.py diff --git a/app/models.py b/app/models.py index 642f4062..e0a544bf 100644 --- a/app/models.py +++ b/app/models.py @@ -2058,7 +2058,7 @@ class UserRegistration(db.Model): class PostVote(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) - author_id = db.Column(db.Integer, db.ForeignKey('user.id')) + author_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True) effect = db.Column(db.Float, index=True) created_at = db.Column(db.DateTime, default=utcnow) @@ -2068,7 +2068,7 @@ class PostVote(db.Model): class PostReplyVote(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) # who voted - author_id = db.Column(db.Integer, db.ForeignKey('user.id')) # the author of the reply voted on - who's reputation is affected + author_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) # the author of the reply voted on - who's reputation is affected post_reply_id = db.Column(db.Integer, db.ForeignKey('post_reply.id'), index=True) effect = db.Column(db.Float) created_at = db.Column(db.DateTime, default=utcnow) diff --git a/migrations/versions/d32ef1893ce4_index_on_vote_author_id.py b/migrations/versions/d32ef1893ce4_index_on_vote_author_id.py new file mode 100644 index 00000000..2bfd336a --- /dev/null +++ b/migrations/versions/d32ef1893ce4_index_on_vote_author_id.py @@ -0,0 +1,50 @@ +"""index on vote.author_id + +Revision ID: d32ef1893ce4 +Revises: 26138ecda7c3 +Create Date: 2024-11-15 16:40:21.080337 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd32ef1893ce4' +down_revision = '26138ecda7c3' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('post_reply_vote', schema=None) as batch_op: + try: + batch_op.create_index(batch_op.f('ix_post_reply_vote_author_id'), ['author_id'], unique=False) + except: + ... + + with op.batch_alter_table('post_vote', schema=None) as batch_op: + try: + batch_op.create_index(batch_op.f('ix_post_vote_author_id'), ['author_id'], unique=False) + except: + ... + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('post_vote', schema=None) as batch_op: + try: + batch_op.drop_index(batch_op.f('ix_post_vote_author_id')) + except: + ... + + with op.batch_alter_table('post_reply_vote', schema=None) as batch_op: + try: + batch_op.drop_index(batch_op.f('ix_post_reply_vote_author_id')) + except: + ... + + # ### end Alembic commands ###