Merge pull request #977 from taigaio/remove-users-table-full-scan

Remove users table full-scan
remotes/origin/fixing-ordering-on-archived
Jesús Espino 2017-04-06 14:56:49 +02:00 committed by GitHub
commit 4d59996620
4 changed files with 45 additions and 9 deletions

View File

@ -323,26 +323,24 @@ def get_related_people(obj):
: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
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
if hasattr(obj, "assigned_to_id") and obj.assigned_to_id:
related_people_q.add(Q(id=obj.assigned_to_id), Q.OR)
## - Watchers
related_people_q.add(_get_q_watchers(obj), Q.OR)
related_people_ids.append(obj.assigned_to_id)
## - 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
related_people = related_people.exclude(is_active=False)
related_people = related_people.exclude(is_system=True)
related_people = related_people.distinct()
return related_people

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-06 06:15
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('timeline', '0006_json_to_jsonb'),
]
operations = [
migrations.AlterIndexTogether(
name='timeline',
index_together=set([('content_type', 'object_id', 'namespace'), ('namespace', 'created')]),
),
]

View File

@ -38,7 +38,8 @@ class Timeline(models.Model):
created = models.DateTimeField(default=timezone.now, db_index=True)
class Meta:
index_together = [('content_type', 'object_id', 'namespace'), ]
index_together = [('content_type', 'object_id', 'namespace'),
('namespace', 'created'),]
# Register all implementations
from .timeline_implementations import *

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-06 07:27
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0023_json_to_jsonb'),
]
operations = [
migrations.RunSQL("CREATE INDEX ON users_user (UPPER('username'))"),
migrations.RunSQL("CREATE INDEX ON users_user (UPPER('email'))"),
]