Remove users table full-scan

remotes/origin/fixing-ordering-on-archived
Jesús Espino 2017-04-05 18:37:14 +02:00
parent ce4739aef3
commit 8f1f001872
1 changed files with 6 additions and 8 deletions

View File

@ -323,26 +323,24 @@ def get_related_people(obj):
:return: User queryset object representing the users related to the object. :return: User queryset object representing the users related to the object.
""" """
related_people_q = Q()
## - Watchers
related_people_ids = list(get_watchers(obj).values_list('id', flat=True))
## - Owner ## - Owner
if hasattr(obj, "owner_id") and obj.owner_id: if hasattr(obj, "owner_id") and obj.owner_id:
related_people_q.add(Q(id=obj.owner_id), Q.OR) related_people_ids.append(obj.owner_id)
## - Assigned to ## - Assigned to
if hasattr(obj, "assigned_to_id") and obj.assigned_to_id: if hasattr(obj, "assigned_to_id") and obj.assigned_to_id:
related_people_q.add(Q(id=obj.assigned_to_id), Q.OR) related_people_ids.append(obj.assigned_to_id)
## - Watchers
related_people_q.add(_get_q_watchers(obj), Q.OR)
## - Apply filters ## - Apply filters
related_people = get_user_model().objects.filter(related_people_q) related_people = get_user_model().objects.filter(id__in=set(related_people_ids))
## - Exclude inactive and system users and remove duplicate ## - Exclude inactive and system users and remove duplicate
related_people = related_people.exclude(is_active=False) related_people = related_people.exclude(is_active=False)
related_people = related_people.exclude(is_system=True) related_people = related_people.exclude(is_system=True)
related_people = related_people.distinct()
return related_people return related_people