diff --git a/analytics/migrations/0008_add_count_indexes.py b/analytics/migrations/0008_add_count_indexes.py new file mode 100644 index 0000000000..f28fdce1b8 --- /dev/null +++ b/analytics/migrations/0008_add_count_indexes.py @@ -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')]), + ), + ] diff --git a/analytics/models.py b/analytics/models.py index 4f5651b2be..92257b8f5d 100644 --- a/analytics/models.py +++ b/analytics/models.py @@ -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():