mirror of https://github.com/zulip/zulip.git
activity: Speed up the main query in /activity.
This commit is contained in:
parent
72d6ff3c3b
commit
f1ceab69c9
|
@ -543,106 +543,70 @@ def realm_summary_table(realm_minutes: Dict[str, float]) -> str:
|
||||||
realm.string_id,
|
realm.string_id,
|
||||||
realm.date_created,
|
realm.date_created,
|
||||||
realm.plan_type,
|
realm.plan_type,
|
||||||
coalesce(user_counts.dau_count, 0) dau_count,
|
coalesce(wau_table.value, 0) wau_count,
|
||||||
coalesce(wau_counts.wau_count, 0) wau_count,
|
coalesce(dau_table.value, 0) dau_count,
|
||||||
(
|
coalesce(user_count_table.value, 0) user_profile_count,
|
||||||
|
coalesce(bot_count_table.value, 0) bot_count
|
||||||
|
FROM
|
||||||
|
zerver_realm as realm
|
||||||
|
LEFT OUTER JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
count(*)
|
value _14day_active_humans,
|
||||||
FROM zerver_userprofile up
|
realm_id
|
||||||
WHERE up.realm_id = realm.id
|
from
|
||||||
AND is_active
|
analytics_realmcount
|
||||||
AND not is_bot
|
|
||||||
) user_profile_count,
|
|
||||||
(
|
|
||||||
SELECT
|
|
||||||
count(*)
|
|
||||||
FROM zerver_userprofile up
|
|
||||||
WHERE up.realm_id = realm.id
|
|
||||||
AND is_active
|
|
||||||
AND is_bot
|
|
||||||
) bot_count
|
|
||||||
FROM zerver_realm realm
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
(
|
|
||||||
SELECT
|
|
||||||
up.realm_id realm_id,
|
|
||||||
count(distinct(ua.user_profile_id)) dau_count
|
|
||||||
FROM zerver_useractivity ua
|
|
||||||
JOIN zerver_userprofile up
|
|
||||||
ON up.id = ua.user_profile_id
|
|
||||||
WHERE
|
WHERE
|
||||||
up.is_active
|
property = 'realm_active_humans::day'
|
||||||
AND (not up.is_bot)
|
AND end_time > now() - interval '25 hours'
|
||||||
AND
|
) as _14day_active_humans_table ON realm.id = _14day_active_humans_table.realm_id
|
||||||
query in (
|
LEFT OUTER JOIN (
|
||||||
'/json/send_message',
|
|
||||||
'send_message_backend',
|
|
||||||
'/api/v1/send_message',
|
|
||||||
'/json/update_pointer',
|
|
||||||
'/json/users/me/pointer',
|
|
||||||
'update_pointer_backend'
|
|
||||||
)
|
|
||||||
AND
|
|
||||||
last_visit > now() - interval '1 day'
|
|
||||||
GROUP BY realm_id
|
|
||||||
) user_counts
|
|
||||||
ON user_counts.realm_id = realm.id
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
(
|
|
||||||
SELECT
|
SELECT
|
||||||
realm_id,
|
value,
|
||||||
count(*) wau_count
|
realm_id
|
||||||
FROM (
|
from
|
||||||
|
analytics_realmcount
|
||||||
|
WHERE
|
||||||
|
property = '7day_actives::day'
|
||||||
|
AND end_time > now() - interval '25 hours'
|
||||||
|
) as wau_table ON realm.id = wau_table.realm_id
|
||||||
|
LEFT OUTER JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
realm.id as realm_id,
|
value,
|
||||||
up.delivery_email
|
realm_id
|
||||||
FROM zerver_useractivity ua
|
from
|
||||||
JOIN zerver_userprofile up
|
analytics_realmcount
|
||||||
ON up.id = ua.user_profile_id
|
|
||||||
JOIN zerver_realm realm
|
|
||||||
ON realm.id = up.realm_id
|
|
||||||
WHERE up.is_active
|
|
||||||
AND (not up.is_bot)
|
|
||||||
AND
|
|
||||||
ua.query in (
|
|
||||||
'/json/send_message',
|
|
||||||
'send_message_backend',
|
|
||||||
'/api/v1/send_message',
|
|
||||||
'/json/update_pointer',
|
|
||||||
'/json/users/me/pointer',
|
|
||||||
'update_pointer_backend'
|
|
||||||
)
|
|
||||||
GROUP by realm.id, up.delivery_email
|
|
||||||
HAVING max(last_visit) > now() - interval '7 day'
|
|
||||||
) as wau_users
|
|
||||||
GROUP BY realm_id
|
|
||||||
) wau_counts
|
|
||||||
ON wau_counts.realm_id = realm.id
|
|
||||||
WHERE
|
WHERE
|
||||||
realm.plan_type = 3
|
property = '1day_actives::day'
|
||||||
OR
|
AND end_time > now() - interval '25 hours'
|
||||||
EXISTS (
|
) as dau_table ON realm.id = dau_table.realm_id
|
||||||
SELECT *
|
LEFT OUTER JOIN (
|
||||||
FROM zerver_useractivity ua
|
SELECT
|
||||||
JOIN zerver_userprofile up
|
value,
|
||||||
ON up.id = ua.user_profile_id
|
realm_id
|
||||||
|
from
|
||||||
|
analytics_realmcount
|
||||||
WHERE
|
WHERE
|
||||||
up.realm_id = realm.id
|
property = 'active_users_audit:is_bot:day'
|
||||||
AND up.is_active
|
AND subgroup = 'false'
|
||||||
AND (not up.is_bot)
|
AND end_time > now() - interval '25 hours'
|
||||||
AND
|
) as user_count_table ON realm.id = user_count_table.realm_id
|
||||||
query in (
|
LEFT OUTER JOIN (
|
||||||
'/json/send_message',
|
SELECT
|
||||||
'/api/v1/send_message',
|
value,
|
||||||
'send_message_backend',
|
realm_id
|
||||||
'/json/update_pointer',
|
from
|
||||||
'/json/users/me/pointer',
|
analytics_realmcount
|
||||||
'update_pointer_backend'
|
WHERE
|
||||||
)
|
property = 'active_users_audit:is_bot:day'
|
||||||
AND
|
AND subgroup = 'true'
|
||||||
last_visit > now() - interval '2 week'
|
AND end_time > now() - interval '25 hours'
|
||||||
)
|
) as bot_count_table ON realm.id = bot_count_table.realm_id
|
||||||
ORDER BY dau_count DESC, string_id ASC
|
WHERE
|
||||||
|
_14day_active_humans IS NOT NULL
|
||||||
|
or realm.plan_type = 3
|
||||||
|
ORDER BY
|
||||||
|
dau_count DESC,
|
||||||
|
string_id ASC
|
||||||
''')
|
''')
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
Loading…
Reference in New Issue