add some probably good indexes
This commit is contained in:
parent
dc45cddf96
commit
cebfab2542
|
@ -0,0 +1,34 @@
|
|||
"""add some probably good indexes (???)
|
||||
|
||||
Revision ID: 6d298e6406f2
|
||||
Revises: 8fac6e10bdb3
|
||||
Create Date: 2017-08-14 20:27:49.103672
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6d298e6406f2'
|
||||
down_revision = '8fac6e10bdb3'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_index(op.f('ix_accounts_last_delete'), 'accounts', ['last_delete'], unique=False)
|
||||
op.create_index(op.f('ix_accounts_last_fetch'), 'accounts', ['last_fetch'], unique=False)
|
||||
op.create_index(op.f('ix_accounts_last_refresh'), 'accounts', ['last_refresh'], unique=False)
|
||||
op.create_index(op.f('ix_oauth_tokens_account_id'), 'oauth_tokens', ['account_id'], unique=False)
|
||||
op.create_index(op.f('ix_posts_author_id'), 'posts', ['author_id'], unique=False)
|
||||
op.create_index(op.f('ix_sessions_account_id'), 'sessions', ['account_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index(op.f('ix_sessions_account_id'), table_name='sessions')
|
||||
op.drop_index(op.f('ix_posts_author_id'), table_name='posts')
|
||||
op.drop_index(op.f('ix_oauth_tokens_account_id'), table_name='oauth_tokens')
|
||||
op.drop_index(op.f('ix_accounts_last_refresh'), table_name='accounts')
|
||||
op.drop_index(op.f('ix_accounts_last_fetch'), table_name='accounts')
|
||||
op.drop_index(op.f('ix_accounts_last_delete'), table_name='accounts')
|
12
model.py
12
model.py
|
@ -52,9 +52,9 @@ class Account(TimestampMixin, RemoteIDMixin):
|
|||
avatar_url = db.Column(db.String)
|
||||
reported_post_count = db.Column(db.Integer)
|
||||
|
||||
last_fetch = db.Column(db.DateTime, server_default='epoch')
|
||||
last_delete = db.Column(db.DateTime, server_default='epoch')
|
||||
last_refresh = db.Column(db.DateTime, server_default='epoch')
|
||||
last_fetch = db.Column(db.DateTime, server_default='epoch', index=True)
|
||||
last_delete = db.Column(db.DateTime, server_default='epoch', index=True)
|
||||
last_refresh = db.Column(db.DateTime, server_default='epoch', index=True)
|
||||
|
||||
def touch_fetch(self):
|
||||
self.last_fetch = db.func.now()
|
||||
|
@ -120,7 +120,7 @@ class OAuthToken(db.Model, TimestampMixin):
|
|||
token = db.Column(db.String, primary_key=True)
|
||||
token_secret = db.Column(db.String, nullable=False)
|
||||
|
||||
account_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=True)
|
||||
account_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=True, index=True)
|
||||
account = db.relationship(Account, backref=db.backref('tokens', order_by=lambda: db.desc(OAuthToken.created_at)))
|
||||
|
||||
# note: account_id is nullable here because we don't know what account a token is for
|
||||
|
@ -132,7 +132,7 @@ class Session(db.Model, TimestampMixin):
|
|||
|
||||
id = db.Column(db.String, primary_key=True, default=lambda: secrets.token_urlsafe())
|
||||
|
||||
account_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False)
|
||||
account_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, index=True)
|
||||
account = db.relationship(Account, lazy='joined', backref='sessions')
|
||||
|
||||
|
||||
|
@ -142,7 +142,7 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin):
|
|||
id = db.Column(db.String, primary_key=True)
|
||||
body = db.Column(db.String)
|
||||
|
||||
author_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False)
|
||||
author_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, index=True)
|
||||
author = db.relationship(Account,
|
||||
backref=db.backref('posts', order_by=lambda: db.desc(Post.created_at)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue