Merge pull request #3363 from quay/add-missing-indexes
Add some missing indexes that should make queries significantly faster
This commit is contained in:
commit
cb677c5711
3 changed files with 68 additions and 3 deletions
|
@ -464,7 +464,7 @@ class BaseModel(ReadSlaveModel):
|
||||||
|
|
||||||
|
|
||||||
class User(BaseModel):
|
class User(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator, max_length=36, null=True)
|
uuid = CharField(default=uuid_generator, max_length=36, null=True, index=True)
|
||||||
username = CharField(unique=True, index=True)
|
username = CharField(unique=True, index=True)
|
||||||
password_hash = CharField(null=True)
|
password_hash = CharField(null=True)
|
||||||
email = CharField(unique=True, index=True,
|
email = CharField(unique=True, index=True,
|
||||||
|
@ -728,7 +728,7 @@ class RepositoryPermission(BaseModel):
|
||||||
|
|
||||||
class PermissionPrototype(BaseModel):
|
class PermissionPrototype(BaseModel):
|
||||||
org = QuayUserField(index=True, backref='orgpermissionproto')
|
org = QuayUserField(index=True, backref='orgpermissionproto')
|
||||||
uuid = CharField(default=uuid_generator)
|
uuid = CharField(default=uuid_generator, index=True)
|
||||||
activating_user = QuayUserField(allows_robots=True, index=True, null=True,
|
activating_user = QuayUserField(allows_robots=True, index=True, null=True,
|
||||||
backref='userpermissionproto')
|
backref='userpermissionproto')
|
||||||
delegate_user = QuayUserField(allows_robots=True, backref='receivingpermission',
|
delegate_user = QuayUserField(allows_robots=True, backref='receivingpermission',
|
||||||
|
@ -769,7 +769,7 @@ class DisableReason(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class RepositoryBuildTrigger(BaseModel):
|
class RepositoryBuildTrigger(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator)
|
uuid = CharField(default=uuid_generator, index=True)
|
||||||
service = ForeignKeyField(BuildTriggerService)
|
service = ForeignKeyField(BuildTriggerService)
|
||||||
repository = ForeignKeyField(Repository)
|
repository = ForeignKeyField(Repository)
|
||||||
connected_user = QuayUserField()
|
connected_user = QuayUserField()
|
||||||
|
@ -923,6 +923,8 @@ class RepositoryTag(BaseModel):
|
||||||
read_slaves = (read_slave,)
|
read_slaves = (read_slave,)
|
||||||
indexes = (
|
indexes = (
|
||||||
(('repository', 'name'), False),
|
(('repository', 'name'), False),
|
||||||
|
(('repository', 'lifetime_start_ts'), False),
|
||||||
|
(('repository', 'lifetime_end_ts'), False),
|
||||||
|
|
||||||
# This unique index prevents deadlocks when concurrently moving and deleting tags
|
# This unique index prevents deadlocks when concurrently moving and deleting tags
|
||||||
(('repository', 'name', 'lifetime_end_ts'), True),
|
(('repository', 'name', 'lifetime_end_ts'), True),
|
||||||
|
@ -1462,6 +1464,9 @@ class Tag(BaseModel):
|
||||||
(('repository', 'name', 'hidden'), False),
|
(('repository', 'name', 'hidden'), False),
|
||||||
(('repository', 'name', 'tag_kind'), False),
|
(('repository', 'name', 'tag_kind'), False),
|
||||||
|
|
||||||
|
(('repository', 'lifetime_start_ms'), False),
|
||||||
|
(('repository', 'lifetime_end_ms'), False),
|
||||||
|
|
||||||
# This unique index prevents deadlocks when concurrently moving and deleting tags
|
# This unique index prevents deadlocks when concurrently moving and deleting tags
|
||||||
(('repository', 'name', 'lifetime_end_ms'), True),
|
(('repository', 'name', 'lifetime_end_ms'), True),
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
"""Add lifetime end indexes to tag tables
|
||||||
|
|
||||||
|
Revision ID: b9045731c4de
|
||||||
|
Revises: e184af42242d
|
||||||
|
Create Date: 2019-02-14 17:18:40.474310
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'b9045731c4de'
|
||||||
|
down_revision = 'e184af42242d'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
def upgrade(tables, tester):
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_index('repositorytag_repository_id_lifetime_end_ts', 'repositorytag', ['repository_id', 'lifetime_end_ts'], unique=False)
|
||||||
|
op.create_index('tag_repository_id_lifetime_end_ms', 'tag', ['repository_id', 'lifetime_end_ms'], unique=False)
|
||||||
|
|
||||||
|
op.create_index('repositorytag_repository_id_lifetime_start_ts', 'repositorytag', ['repository_id', 'lifetime_start_ts'], unique=False)
|
||||||
|
op.create_index('tag_repository_id_lifetime_start_ms', 'tag', ['repository_id', 'lifetime_start_ms'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(tables, tester):
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('tag_repository_id_lifetime_end_ms', table_name='tag')
|
||||||
|
op.drop_index('repositorytag_repository_id_lifetime_end_ts', table_name='repositorytag')
|
||||||
|
|
||||||
|
op.drop_index('tag_repository_id_lifetime_start_ms', table_name='tag')
|
||||||
|
op.drop_index('repositorytag_repository_id_lifetime_start_ts', table_name='repositorytag')
|
||||||
|
# ### end Alembic commands ###
|
|
@ -0,0 +1,28 @@
|
||||||
|
"""Add missing index on UUID fields
|
||||||
|
|
||||||
|
Revision ID: e184af42242d
|
||||||
|
Revises: 6ec8726c0ace
|
||||||
|
Create Date: 2019-02-14 16:35:47.768086
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'e184af42242d'
|
||||||
|
down_revision = '6ec8726c0ace'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
def upgrade(tables, tester):
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_index('permissionprototype_uuid', 'permissionprototype', ['uuid'], unique=False)
|
||||||
|
op.create_index('repositorybuildtrigger_uuid', 'repositorybuildtrigger', ['uuid'], unique=False)
|
||||||
|
op.create_index('user_uuid', 'user', ['uuid'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(tables, tester):
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('user_uuid', table_name='user')
|
||||||
|
op.drop_index('repositorybuildtrigger_uuid', table_name='repositorybuildtrigger')
|
||||||
|
op.drop_index('permissionprototype_uuid', table_name='permissionprototype')
|
||||||
|
# ### end Alembic commands ###
|
Reference in a new issue