Commit ecaabe17 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

astakos: Avoid multiple user lookups in quota sync

Also, remove unneeded param of astakos_users_quotas.
parent 4421ebfc
......@@ -161,9 +161,10 @@ class Command(SynnefoCommand):
self.stdout.write("No sync needed.\n")
else:
self.stdout.write("Synced %s users:\n" % size)
for holder in diff_quotas.keys():
user = get_user_by_uuid(holder)
self.stdout.write("%s (%s)\n" % (holder, user.username))
uuids = diff_quotas.keys()
users = AstakosUser.objects.filter(uuid__in=uuids)
for user in users:
self.stdout.write("%s (%s)\n" % (user.uuid, user.username))
def print_verify(self,
qh_limits,
......
......@@ -183,8 +183,9 @@ def initial_quotas(users):
source_quota = {SYSTEM: dict(default_quotas)}
initial[uuid] = source_quota
userids = [user.pk for user in users]
objs = AstakosUserQuota.objects.select_related()
orig_quotas = objs.filter(user__in=users)
orig_quotas = objs.filter(user__pk__in=userids)
for user_quota in orig_quotas:
uuid = user_quota.user.uuid
user_init = initial.get(uuid, {})
......@@ -201,18 +202,16 @@ def get_grant_source(grant):
return SYSTEM
def astakos_users_quotas(users, initial=None):
def astakos_users_quotas(users):
users = list(users)
if initial is None:
quotas = initial_quotas(users)
else:
quotas = copy.deepcopy(initial)
quotas = initial_quotas(users)
userids = [user.pk for user in users]
ACTUALLY_ACCEPTED = ProjectMembership.ACTUALLY_ACCEPTED
objs = ProjectMembership.objects.select_related(
'project', 'person', 'project__application')
memberships = objs.filter(
person__in=users,
person__pk__in=userids,
state__in=ACTUALLY_ACCEPTED,
project__state=Project.NORMAL,
project__application__state=ProjectApplication.APPROVED)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment