Use a UNION query instead of a multitude of left outer joins for performance reasons.
Fixes #159
This commit is contained in:
parent
03e1636ff2
commit
5f1d23c6e8
3 changed files with 24 additions and 15 deletions
|
@ -1156,18 +1156,27 @@ def update_email(user, new_email, auto_verify=False):
|
|||
def get_all_user_permissions(user):
|
||||
UserThroughTeam = User.alias()
|
||||
|
||||
return (RepositoryPermission
|
||||
.select(RepositoryPermission, Role, Repository, Namespace)
|
||||
.join(Role)
|
||||
.switch(RepositoryPermission)
|
||||
.join(Repository)
|
||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||
.switch(RepositoryPermission)
|
||||
.join(User, JOIN_LEFT_OUTER)
|
||||
.switch(RepositoryPermission)
|
||||
.join(Team, JOIN_LEFT_OUTER).join(TeamMember, JOIN_LEFT_OUTER)
|
||||
.join(UserThroughTeam, JOIN_LEFT_OUTER, on=(UserThroughTeam.id == TeamMember.user))
|
||||
.where((User.id == user) | (UserThroughTeam.id == user)))
|
||||
base_query = (RepositoryPermission
|
||||
.select(RepositoryPermission, Role, Repository, Namespace)
|
||||
.join(Role)
|
||||
.switch(RepositoryPermission)
|
||||
.join(Repository)
|
||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||
.switch(RepositoryPermission))
|
||||
|
||||
direct = (base_query
|
||||
.clone()
|
||||
.join(User)
|
||||
.where(User.id == user))
|
||||
|
||||
team = (base_query
|
||||
.clone()
|
||||
.join(Team)
|
||||
.join(TeamMember)
|
||||
.join(UserThroughTeam, on=(UserThroughTeam.id == TeamMember.user))
|
||||
.where(UserThroughTeam.id == user))
|
||||
|
||||
return direct | team
|
||||
|
||||
|
||||
def delete_prototype_permission(org, uid):
|
||||
|
@ -1232,7 +1241,7 @@ def get_org_wide_permissions(user):
|
|||
|
||||
|
||||
def get_all_repo_teams(namespace_name, repository_name):
|
||||
return (RepositoryPermission.select(Team.name.alias('team_name'), Role.name, RepositoryPermission)
|
||||
return (RepositoryPermission.select(Team.name, Role.name, RepositoryPermission)
|
||||
.join(Team)
|
||||
.switch(RepositoryPermission)
|
||||
.join(Role)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
autobahn==0.9.3-3
|
||||
aiowsgi
|
||||
trollius
|
||||
peewee
|
||||
flask
|
||||
py-bcrypt
|
||||
Flask-Principal
|
||||
|
@ -40,6 +39,7 @@ git+https://github.com/DevTable/anunidecode.git
|
|||
git+https://github.com/DevTable/pygithub.git
|
||||
git+https://github.com/DevTable/container-cloud-config.git
|
||||
git+https://github.com/DevTable/python-etcd.git@sslfix
|
||||
git+https://github.com/coreos/peewee.git
|
||||
git+https://github.com/coreos/py-bitbucket.git
|
||||
git+https://github.com/coreos/pyapi-gitlab.git
|
||||
git+https://github.com/coreos/mockldap.git
|
||||
|
|
|
@ -56,7 +56,6 @@ oslo.serialization==1.5.0
|
|||
oslo.utils==1.5.0
|
||||
paramiko==1.15.2
|
||||
pbr==0.11.0
|
||||
peewee==2.6.0
|
||||
prettytable==0.7.2
|
||||
psutil==2.2.1
|
||||
psycopg2==2.6
|
||||
|
@ -95,6 +94,7 @@ git+https://github.com/DevTable/pygithub.git
|
|||
git+https://github.com/DevTable/container-cloud-config.git
|
||||
git+https://github.com/DevTable/python-etcd.git@sslfix
|
||||
git+https://github.com/NateFerrero/oauth2lib.git
|
||||
git+https://github.com/coreos/peewee.git
|
||||
git+https://github.com/coreos/py-bitbucket.git
|
||||
git+https://github.com/coreos/pyapi-gitlab.git
|
||||
git+https://github.com/coreos/mockldap.git
|
Reference in a new issue