~minus/stewdio-api

9f5e2e883337b044bcdd6f4bb8c0eed753181792 — minus 6 years ago 564c9f3
Add indexes on taggings and favorites

to improve performance with lots of tags/favorites
A alembic/versions/bf4bf948f860_add_indexes.py => alembic/versions/bf4bf948f860_add_indexes.py +26 -0
@@ 0,0 1,26 @@
"""add indexes

Revision ID: bf4bf948f860
Revises: e43080100a6f
Create Date: 2018-09-22 11:38:52.159738

"""

# revision identifiers, used by Alembic.
revision = 'bf4bf948f860'
down_revision = 'e43080100a6f'

from alembic import op

def upgrade():
    op.create_index('taggings_tag_idx', 'taggings', ['tag'], unique=False)
    op.create_index('taggings_song_idx', 'taggings', ['song'], unique=False)
    op.create_index('favorites_user_id_idx', 'favorites', ['user_id'], unique=False)
    op.create_index('favorites_song_idx', 'favorites', ['song'], unique=False)


def downgrade():
    op.drop_index('favorites_song_idx', table_name='favorites')
    op.drop_index('favorites_user_id_idx', table_name='favorites')
    op.drop_index('taggings_song_idx', table_name='taggings')
    op.drop_index('taggings_tag_idx', table_name='taggings')

M stewdio/types/favorite.py => stewdio/types/favorite.py +2 -2
@@ 3,7 3,7 @@ from ..database import Base

favorites = sa.Table("favorites", Base.metadata,
    sa.Column("id", sa.Integer, primary_key=True),
    sa.Column("user_id", sa.Integer, sa.ForeignKey("users.id"), nullable=False),
    sa.Column("song", sa.Integer, sa.ForeignKey("songs.id"), nullable=False),
    sa.Column("user_id", sa.Integer, sa.ForeignKey("users.id"), nullable=False, index=True),
    sa.Column("song", sa.Integer, sa.ForeignKey("songs.id"), nullable=False, index=True),
    sa.schema.Index("uniq_favorite", "user_id", "song", unique=True)
)

M stewdio/types/tagging.py => stewdio/types/tagging.py +3 -3
@@ 3,6 3,6 @@ import sqlalchemy as sa
from stewdio.database import Base

taggings = sa.Table("taggings", Base.metadata,
    sa.Column("song", sa.Integer, sa.ForeignKey("songs.id"), nullable=False),
    sa.Column("tag", sa.Integer, sa.ForeignKey("tags.id"), nullable=False)
)
\ No newline at end of file
    sa.Column("song", sa.Integer, sa.ForeignKey("songs.id"), nullable=False, index=True),
    sa.Column("tag", sa.Integer, sa.ForeignKey("tags.id"), nullable=False, index=True)
)