Exclude dormant users from buddy list queries.

If a user has not shown activity in two weeks, we exclude
them from the buddy list.  This should help performance for
large realms and mobile clients.
This commit is contained in:
Steve Howell
2017-02-19 07:43:32 -08:00
committed by Tim Abbott
parent 2420df8415
commit 3a332aee0b
2 changed files with 46 additions and 1 deletions

View File

@@ -1430,6 +1430,12 @@ class UserPresence(models.Model):
return UserPresence.get_status_dicts_for_query(query, mobile_user_ids)
@staticmethod
def exclude_old_users(query):
# type: (QuerySet) -> QuerySet
two_weeks_ago = timezone.now() - datetime.timedelta(weeks=2)
return query.filter(timestamp__gte=two_weeks_ago)
@staticmethod
def get_status_dict_by_realm(realm_id):
# type: (int) -> DefaultDict[Any, Dict[Any, Any]]
@@ -1437,7 +1443,11 @@ class UserPresence(models.Model):
user_profile__realm_id=realm_id,
user_profile__is_active=True,
user_profile__is_bot=False
).values(
)
query = UserPresence.exclude_old_users(query)
query = query.values(
'client__name',
'status',
'timestamp',