Merge pull request #2961 from coreos-inc/joseph.schorr/QS-107/create-repo-opt
Small optimizations around create repository code
This commit is contained in:
commit
d8fde005d8
3 changed files with 12 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -33,23 +33,27 @@ def get_public_repo_visibility():
|
|||
return _basequery.get_public_repo_visibility()
|
||||
|
||||
|
||||
def create_repository(namespace, name, creating_user, visibility='private', repo_kind='image'):
|
||||
private = Visibility.get(name=visibility)
|
||||
def create_repository(namespace, name, creating_user, visibility='private', repo_kind='image',
|
||||
description=None):
|
||||
namespace_user = User.get(username=namespace)
|
||||
repo = Repository.create(name=name, visibility=private, namespace_user=namespace_user,
|
||||
kind=Repository.kind.get_id(repo_kind))
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -126,8 +126,7 @@ class PreOCIModel(RepositoryDataInterface):
|
|||
def create_repo(self, namespace_name, repository_name, owner, description, visibility='private',
|
||||
repo_kind='image'):
|
||||
repo = model.repository.create_repository(namespace_name, repository_name, owner, visibility,
|
||||
repo_kind=repo_kind)
|
||||
model.repository.set_description(repo, description)
|
||||
repo_kind=repo_kind, description=description)
|
||||
return Repository(namespace_name, repository_name)
|
||||
|
||||
def get_repo(self, namespace_name, repository_name, user):
|
||||
|
|
Reference in a new issue