Add various missing indexes

Indexes added:

Image::repository - Needed for model.image.get_repository_images_without_placements
RepositoryTag::image - Needed for model.tag.get_tags_for_image
RepositoryTag::repository - Needed for repository deletion
RepositoryBuild::phase - Needed for model.build.list_repository_builds sorting
RepositoryBuild::started - Needed for model.build.list_repository_builds sorting
RepositoryBuild::repository+started+phase - Needed for model.build.list_repository_builds
RepositoryBuild::started+logs_archived+phase - Needed for model.build.get_archivable_build lookup
This commit is contained in:
Joseph Schorr 2016-08-03 17:11:28 -04:00
parent 432bdc7e3e
commit 80a37fd295
2 changed files with 62 additions and 25 deletions

View file

@ -347,7 +347,7 @@ class Team(BaseModel):
class TeamMember(BaseModel):
user = QuayUserField(allows_robots=True, index=True)
team = ForeignKeyField(Team, index=True)
team = ForeignKeyField(Team)
class Meta:
database = db
@ -362,7 +362,7 @@ class TeamMemberInvite(BaseModel):
# Note: Either user OR email will be filled in, but not both.
user = QuayUserField(index=True, null=True)
email = CharField(null=True)
team = ForeignKeyField(Team, index=True)
team = ForeignKeyField(Team)
inviter = ForeignKeyField(User, related_name='inviter')
invite_token = CharField(default=urn_generator(['teaminvite']))
@ -373,7 +373,7 @@ class LoginService(BaseModel):
class FederatedLogin(BaseModel):
user = QuayUserField(allows_robots=True, index=True)
service = ForeignKeyField(LoginService, index=True)
service = ForeignKeyField(LoginService)
service_ident = CharField()
metadata_json = TextField(default='{}')
@ -421,8 +421,8 @@ class Repository(BaseModel):
class Star(BaseModel):
user = ForeignKeyField(User, index=True)
repository = ForeignKeyField(Repository, index=True)
user = ForeignKeyField(User)
repository = ForeignKeyField(Repository)
created = DateTimeField(default=datetime.now)
class Meta:
@ -439,9 +439,9 @@ class Role(BaseModel):
class RepositoryPermission(BaseModel):
team = ForeignKeyField(Team, index=True, null=True)
user = QuayUserField(allows_robots=True, index=True, null=True)
repository = ForeignKeyField(Repository, index=True)
team = ForeignKeyField(Team, null=True)
user = QuayUserField(allows_robots=True, null=True)
repository = ForeignKeyField(Repository)
role = ForeignKeyField(Role)
class Meta:
@ -493,8 +493,8 @@ class BuildTriggerService(BaseModel):
class RepositoryBuildTrigger(BaseModel):
uuid = CharField(default=uuid_generator)
service = ForeignKeyField(BuildTriggerService, index=True)
repository = ForeignKeyField(Repository, index=True)
service = ForeignKeyField(BuildTriggerService)
repository = ForeignKeyField(Repository)
connected_user = QuayUserField()
auth_token = CharField(null=True)
private_key = TextField(null=True)
@ -531,7 +531,7 @@ class ImageStorageSignatureKind(BaseModel):
class ImageStorageSignature(BaseModel):
storage = ForeignKeyField(ImageStorage, index=True)
storage = ForeignKeyField(ImageStorage)
kind = ForeignKeyField(ImageStorageSignatureKind)
signature = TextField(null=True)
uploading = BooleanField(default=True, null=True)
@ -584,7 +584,7 @@ class Image(BaseModel):
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
ancestors = CharField(index=True, default='/', max_length=64535, null=True)
storage = ForeignKeyField(ImageStorage, index=True, null=True)
storage = ForeignKeyField(ImageStorage, null=True)
created = DateTimeField(null=True)
comment = TextField(null=True)
@ -597,7 +597,7 @@ class Image(BaseModel):
security_indexed_engine = IntegerField(default=-1, index=True)
# We use a proxy here instead of 'self' in order to disable the foreign key constraint
parent = ForeignKeyField(_ImageProxy, index=True, null=True, related_name='children')
parent = ForeignKeyField(_ImageProxy, null=True, related_name='children')
class Meta:
database = db
@ -648,7 +648,7 @@ class RepositoryTag(BaseModel):
class TagManifest(BaseModel):
tag = ForeignKeyField(RepositoryTag, index=True, unique=True)
tag = ForeignKeyField(RepositoryTag, unique=True)
digest = CharField(index=True)
json_data = TextField()
@ -683,30 +683,38 @@ class QueueItem(BaseModel):
class RepositoryBuild(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
access_token = ForeignKeyField(AccessToken)
resource_key = CharField(index=True, null=True)
job_config = TextField()
phase = CharField(default=BUILD_PHASE.WAITING)
started = DateTimeField(default=datetime.now)
started = DateTimeField(default=datetime.now, index=True)
display_name = CharField()
trigger = ForeignKeyField(RepositoryBuildTrigger, null=True, index=True)
trigger = ForeignKeyField(RepositoryBuildTrigger, null=True)
pull_robot = QuayUserField(null=True, related_name='buildpullrobot', allows_robots=True,
robot_null_delete=True)
logs_archived = BooleanField(default=False)
queue_id = CharField(null=True, index=True)
class Meta:
database = db
read_slaves = (read_slave,)
indexes = (
(('repository', 'started', 'phase'), False),
(('started', 'logs_archived', 'phase'), False),
)
class LogEntryKind(BaseModel):
name = CharField(index=True, unique=True)
class LogEntry(BaseModel):
kind = ForeignKeyField(LogEntryKind, index=True)
kind = ForeignKeyField(LogEntryKind)
account = QuayUserField(index=True, related_name='account')
performer = QuayUserField(allows_robots=True, index=True, null=True,
related_name='performer', robot_null_delete=True)
repository = ForeignKeyField(Repository, index=True, null=True)
repository = ForeignKeyField(Repository, null=True)
datetime = DateTimeField(default=datetime.now, index=True)
ip = CharField(null=True)
metadata_json = TextField(default='{}')
@ -724,7 +732,7 @@ class LogEntry(BaseModel):
class RepositoryActionCount(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
count = IntegerField()
date = DateField(index=True)
@ -774,7 +782,7 @@ class NotificationKind(BaseModel):
class Notification(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
kind = ForeignKeyField(NotificationKind, index=True)
kind = ForeignKeyField(NotificationKind)
target = QuayUserField(index=True)
metadata_json = TextField(default='{}')
created = DateTimeField(default=datetime.now, index=True)
@ -792,7 +800,7 @@ class ExternalNotificationMethod(BaseModel):
class RepositoryNotification(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
event = ForeignKeyField(ExternalNotificationEvent)
method = ForeignKeyField(ExternalNotificationMethod)
title = CharField(null=True)
@ -801,7 +809,7 @@ class RepositoryNotification(BaseModel):
class RepositoryAuthorizedEmail(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
email = CharField()
code = CharField(default=random_string_generator(), unique=True, index=True)
confirmed = BooleanField(default=False)
@ -816,7 +824,7 @@ class RepositoryAuthorizedEmail(BaseModel):
class BlobUpload(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
uuid = CharField(index=True, unique=True)
byte_count = IntegerField(default=0)
sha_state = ResumableSHA256Field(null=True, default=resumablehashlib.sha256)
@ -903,7 +911,7 @@ class ServiceKey(BaseModel):
created_date = DateTimeField(default=datetime.utcnow)
expiration_date = DateTimeField(null=True)
rotation_duration = IntegerField(null=True)
approval = ForeignKeyField(ServiceKeyApproval, index=True, null=True)
approval = ForeignKeyField(ServiceKeyApproval, null=True)
is_model = lambda x: inspect.isclass(x) and issubclass(x, BaseModel) and x is not BaseModel

View file

@ -0,0 +1,29 @@
"""Add missing indexes
Revision ID: 790d91952fa8
Revises: 1093d8b212bb
Create Date: 2016-08-03 17:05:06.675520
"""
# revision identifiers, used by Alembic.
revision = '790d91952fa8'
down_revision = '1093d8b212bb'
from alembic import op
import sqlalchemy as sa
def upgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.create_index('repositorybuild_repository_id_started_phase', 'repositorybuild', ['repository_id', 'started', 'phase'], unique=False)
op.create_index('repositorybuild_started', 'repositorybuild', ['started'], unique=False)
op.create_index('repositorybuild_started_logs_archived_phase', 'repositorybuild', ['started', 'logs_archived', 'phase'], unique=False)
### end Alembic commands ###
def downgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.drop_index('repositorybuild_started_logs_archived_phase', table_name='repositorybuild')
op.drop_index('repositorybuild_started', table_name='repositorybuild')
op.drop_index('repositorybuild_repository_id_started_phase', table_name='repositorybuild')
### end Alembic commands ###