analytics: Fix count_stream_by_realm.

Add a join clause on zerver_message in count_stream_by_realm,
otherwise we only output the final total streamcount for a realm
for every time entry.
This commit is contained in:
umkay 2016-10-17 17:03:57 -07:00 committed by Tim Abbott
parent 49b23ea84a
commit 87d22c9e4d
1 changed files with 11 additions and 7 deletions

View File

@ -255,18 +255,22 @@ count_message_by_stream_query = """
zerver_count_message_by_stream = ZerverCountQuery(Message, StreamCount, count_message_by_stream_query) zerver_count_message_by_stream = ZerverCountQuery(Message, StreamCount, count_message_by_stream_query)
count_stream_by_realm_query = """ count_stream_by_realm_query = """
INSERT INTO analytics_realmcount INSERT INTO analytics_realmcount
(realm_id, value, property, end_time, interval) (realm_id, value, property, end_time, interval)
SELECT SELECT
zerver_stream.realm_id, count(*), '%(property)s', %%(time_end)s, '%(interval)s' zerver_realm.id, count(*), '%(property)s', %%(time_end)s, '%(interval)s'
FROM zerver_stream FROM zerver_realm
LEFT JOIN zerver_recipient LEFT JOIN zerver_stream
ON ON
( (
zerver_recipient.type = 2 AND zerver_stream.realm_id = zerver_realm.id AND
zerver_stream.id = zerver_recipient.type_id zerver_stream.date_created >= %%(time_start)s AND
zerver_stream.date_created < %%(time_end)s
%(join_args)s
) )
GROUP BY zerver_stream.realm_id WHERE
zerver_realm.date_created < %%(time_end)s
GROUP BY zerver_realm.id
""" """
zerver_count_stream_by_realm = ZerverCountQuery(Stream, RealmCount, count_stream_by_realm_query) zerver_count_stream_by_realm = ZerverCountQuery(Stream, RealmCount, count_stream_by_realm_query)