analytics: Add indexes to optimize performance of aggregation.

These indexes fix some slow queries used in updating the analytics
tables, resulting in the analytics system consuming far less total
resources.
This commit is contained in:
Tim Abbott 2017-02-01 14:29:55 -08:00
parent 5ec4ed0d5c
commit b7df84d5a8
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-01 22:28
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('zerver', '0050_userprofile_avatar_version'),
('analytics', '0007_remove_interval'),
]
operations = [
migrations.AlterIndexTogether(
name='realmcount',
index_together=set([('property', 'end_time')]),
),
migrations.AlterIndexTogether(
name='streamcount',
index_together=set([('property', 'realm', 'end_time')]),
),
migrations.AlterIndexTogether(
name='usercount',
index_together=set([('property', 'realm', 'end_time')]),
),
]

View File

@ -86,6 +86,7 @@ class RealmCount(BaseCount):
class Meta(object):
unique_together = ("realm", "property", "subgroup", "end_time")
index_together = ["property", "end_time"]
@staticmethod
def extended_id():
@ -107,6 +108,9 @@ class UserCount(BaseCount):
class Meta(object):
unique_together = ("user", "property", "subgroup", "end_time")
# This index dramatically improves the performance of
# aggregating from users to realms
index_together = ["property", "realm", "end_time"]
@staticmethod
def extended_id():
@ -128,6 +132,9 @@ class StreamCount(BaseCount):
class Meta(object):
unique_together = ("stream", "property", "subgroup", "end_time")
# This index dramatically improves the performance of
# aggregating from streams to realms
index_together = ["property", "realm", "end_time"]
@staticmethod
def extended_id():