Reduce the number of DB queries for creating a repo

This commit is contained in:
Joseph Schorr 2018-01-04 14:32:39 -05:00
parent 1e1bec0afe
commit 3f99e864e1
2 changed files with 9 additions and 6 deletions

View file

@ -574,7 +574,7 @@ class RepositoryKind(BaseModel):
class Repository(BaseModel):
namespace_user = QuayUserField(null=True)
name = FullIndexedCharField(match_function=db_match_func)
visibility = ForeignKeyField(Visibility)
visibility = EnumField(Visibility)
description = FullIndexedTextField(match_function=db_match_func, null=True)
badge_token = CharField(default=uuid_generator)
kind = EnumField(RepositoryKind)

View file

@ -35,22 +35,25 @@ def get_public_repo_visibility():
def create_repository(namespace, name, creating_user, visibility='private', repo_kind='image',
description=None):
private = Visibility.get(name=visibility)
namespace_user = User.get(username=namespace)
repo = Repository.create(name=name, visibility=private, namespace_user=namespace_user,
kind=Repository.kind.get_id(repo_kind), description=description)
admin = Role.get(name='admin')
yesterday = datetime.now() - timedelta(days=1)
repo = Repository.create(name=name, visibility=Repository.visibility.get_id(visibility),
namespace_user=namespace_user,
kind=Repository.kind.get_id(repo_kind),
description=description)
RepositoryActionCount.create(repository=repo, count=0, date=yesterday)
RepositorySearchScore.create(repository=repo, score=0)
if creating_user and not creating_user.organization:
admin = Role.get(name='admin')
RepositoryPermission.create(user=creating_user, repository=repo, role=admin)
if creating_user.username != namespace:
# Permission prototypes only work for orgs
permission.apply_default_permissions(repo, creating_user)
return repo