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):
|
def get_all_user_permissions(user):
|
||||||
UserThroughTeam = User.alias()
|
UserThroughTeam = User.alias()
|
||||||
|
|
||||||
return (RepositoryPermission
|
base_query = (RepositoryPermission
|
||||||
.select(RepositoryPermission, Role, Repository, Namespace)
|
.select(RepositoryPermission, Role, Repository, Namespace)
|
||||||
.join(Role)
|
.join(Role)
|
||||||
.switch(RepositoryPermission)
|
.switch(RepositoryPermission)
|
||||||
.join(Repository)
|
.join(Repository)
|
||||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||||
.switch(RepositoryPermission)
|
.switch(RepositoryPermission))
|
||||||
.join(User, JOIN_LEFT_OUTER)
|
|
||||||
.switch(RepositoryPermission)
|
direct = (base_query
|
||||||
.join(Team, JOIN_LEFT_OUTER).join(TeamMember, JOIN_LEFT_OUTER)
|
.clone()
|
||||||
.join(UserThroughTeam, JOIN_LEFT_OUTER, on=(UserThroughTeam.id == TeamMember.user))
|
.join(User)
|
||||||
.where((User.id == user) | (UserThroughTeam.id == 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):
|
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):
|
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)
|
.join(Team)
|
||||||
.switch(RepositoryPermission)
|
.switch(RepositoryPermission)
|
||||||
.join(Role)
|
.join(Role)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
autobahn==0.9.3-3
|
autobahn==0.9.3-3
|
||||||
aiowsgi
|
aiowsgi
|
||||||
trollius
|
trollius
|
||||||
peewee
|
|
||||||
flask
|
flask
|
||||||
py-bcrypt
|
py-bcrypt
|
||||||
Flask-Principal
|
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/pygithub.git
|
||||||
git+https://github.com/DevTable/container-cloud-config.git
|
git+https://github.com/DevTable/container-cloud-config.git
|
||||||
git+https://github.com/DevTable/python-etcd.git@sslfix
|
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/py-bitbucket.git
|
||||||
git+https://github.com/coreos/pyapi-gitlab.git
|
git+https://github.com/coreos/pyapi-gitlab.git
|
||||||
git+https://github.com/coreos/mockldap.git
|
git+https://github.com/coreos/mockldap.git
|
||||||
|
|
|
@ -56,7 +56,6 @@ oslo.serialization==1.5.0
|
||||||
oslo.utils==1.5.0
|
oslo.utils==1.5.0
|
||||||
paramiko==1.15.2
|
paramiko==1.15.2
|
||||||
pbr==0.11.0
|
pbr==0.11.0
|
||||||
peewee==2.6.0
|
|
||||||
prettytable==0.7.2
|
prettytable==0.7.2
|
||||||
psutil==2.2.1
|
psutil==2.2.1
|
||||||
psycopg2==2.6
|
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/container-cloud-config.git
|
||||||
git+https://github.com/DevTable/python-etcd.git@sslfix
|
git+https://github.com/DevTable/python-etcd.git@sslfix
|
||||||
git+https://github.com/NateFerrero/oauth2lib.git
|
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/py-bitbucket.git
|
||||||
git+https://github.com/coreos/pyapi-gitlab.git
|
git+https://github.com/coreos/pyapi-gitlab.git
|
||||||
git+https://github.com/coreos/mockldap.git
|
git+https://github.com/coreos/mockldap.git
|
Reference in a new issue