Merge pull request #170 from jakedt/unionpermission
Use a UNION query instead of multiple left outer joins
This commit is contained in:
commit
7c817e61dd
5 changed files with 27 additions and 17 deletions
|
@ -269,7 +269,7 @@ def on_identity_loaded(sender, identity):
|
|||
repo_grant = _RepositoryNeed(token_data.repository.namespace_user.username,
|
||||
token_data.repository.name,
|
||||
token_data.role.name)
|
||||
logger.debug('Delegate token added permission: {0}'.format(repo_grant))
|
||||
logger.debug('Delegate token added permission: %s', repo_grant)
|
||||
identity.provides.add(repo_grant)
|
||||
|
||||
elif identity.auth_type == 'signed_grant':
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -22,7 +22,6 @@ from util.cache import no_cache
|
|||
from endpoints.common import common_login, render_page_template, route_show_if, param_required
|
||||
from endpoints.decorators import anon_protect
|
||||
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
||||
from endpoints.registry import set_cache_headers
|
||||
from endpoints.trigger import (CustomBuildTrigger, BitbucketBuildTrigger, TriggerProviderException,
|
||||
BuildTriggerHandler)
|
||||
from util.names import parse_repository_name, parse_repository_name_and_tag
|
||||
|
@ -34,8 +33,10 @@ from auth import scopes
|
|||
import features
|
||||
import json
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Capture the unverified SSL errors.
|
||||
logging.captureWarnings(True)
|
||||
|
||||
|
|
|
@ -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