model: index comments by thread for faster lookup
This commit is contained in:
parent
daadd21877
commit
b00d44ddc1
|
@ -15,7 +15,7 @@ class Comment(Post):
|
|||
|
||||
# Parent thread
|
||||
thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'),
|
||||
nullable=False)
|
||||
nullable=False, index=True)
|
||||
thread = db.relationship('Thread',
|
||||
backref=backref('comments', lazy='dynamic'),
|
||||
foreign_keys=thread_id)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
"""Index coments by thread
|
||||
|
||||
Revision ID: 0abd1c81e3aa
|
||||
Revises: 44c2e37ef899
|
||||
Create Date: 2021-07-07 16:26:23.230696
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0abd1c81e3aa'
|
||||
down_revision = '44c2e37ef899'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_index(op.f('ix_comment_thread_id'), 'comment', ['thread_id'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_comment_thread_id'), table_name='comment')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue