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

@ -258,15 +258,19 @@ count_stream_by_realm_query = """
INSERT INTO analytics_realmcount
(realm_id, value, property, end_time, interval)
SELECT
zerver_stream.realm_id, count(*), '%(property)s', %%(time_end)s, '%(interval)s'
FROM zerver_stream
LEFT JOIN zerver_recipient
zerver_realm.id, count(*), '%(property)s', %%(time_end)s, '%(interval)s'
FROM zerver_realm
LEFT JOIN zerver_stream
ON
(
zerver_recipient.type = 2 AND
zerver_stream.id = zerver_recipient.type_id
zerver_stream.realm_id = zerver_realm.id AND
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)