From da4b54d414fd1fa6837d7493ba8ee3b267deef26 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Thu, 5 Oct 2023 20:06:16 +0200 Subject: [PATCH] analytics: Remove out of date tabs from main activity page. Removes the various 'ad_hoc_queries' in the main activity page that no longer have relevant data or information. --- analytics/tests/test_activity_views.py | 2 +- analytics/views/installation_activity.py | 118 +---------------------- 2 files changed, 3 insertions(+), 117 deletions(-) diff --git a/analytics/tests/test_activity_views.py b/analytics/tests/test_activity_views.py index ad2473b7cd..23a7bbd59b 100644 --- a/analytics/tests/test_activity_views.py +++ b/analytics/tests/test_activity_views.py @@ -31,7 +31,7 @@ class ActivityTest(ZulipTestCase): user_profile.is_staff = True user_profile.save(update_fields=["is_staff"]) - with self.assert_database_query_count(16): + with self.assert_database_query_count(12): result = self.client_get("/activity") self.assertEqual(result.status_code, 200) diff --git a/analytics/views/installation_activity.py b/analytics/views/installation_activity.py index 8d5410279d..289d559db6 100644 --- a/analytics/views/installation_activity.py +++ b/analytics/views/installation_activity.py @@ -3,7 +3,7 @@ import time from collections import defaultdict from contextlib import suppress from datetime import timedelta -from typing import Dict, List, Optional, Tuple +from typing import Dict, Optional, Tuple from django.conf import settings from django.db import connection @@ -12,7 +12,7 @@ from django.shortcuts import render from django.template import loader from django.utils.timezone import now as timezone_now from markupsafe import Markup -from psycopg2.sql import SQL, Composable, Literal +from psycopg2.sql import SQL from analytics.lib.counts import COUNT_STATS from analytics.views.activity_common import ( @@ -353,119 +353,6 @@ def user_activity_intervals() -> Tuple[Markup, Dict[str, float]]: return content, realm_minutes -def ad_hoc_queries() -> List[Dict[str, str]]: - pages = [] - - for mobile_type in ["Android", "ZulipiOS"]: - title = f"{mobile_type} usage" - - query: Composable = SQL( - """ - select - realm.string_id, - up.id user_id, - client.name, - sum(count) as hits, - max(last_visit) as last_time - from zerver_useractivity ua - join zerver_client client on client.id = ua.client_id - join zerver_userprofile up on up.id = ua.user_profile_id - join zerver_realm realm on realm.id = up.realm_id - where - client.name like {mobile_type} - group by string_id, up.id, client.name - having max(last_visit) > now() - interval '2 week' - order by string_id, up.id, client.name - """ - ).format( - mobile_type=Literal(mobile_type), - ) - - cols = [ - "Realm", - "User id", - "Name", - "Hits", - "Last time", - ] - - pages.append(get_page(query, cols, title)) - - ### - - title = "Desktop users" - - query = SQL( - """ - select - realm.string_id, - client.name, - sum(count) as hits, - max(last_visit) as last_time - from zerver_useractivity ua - join zerver_client client on client.id = ua.client_id - join zerver_userprofile up on up.id = ua.user_profile_id - join zerver_realm realm on realm.id = up.realm_id - where - client.name like 'desktop%%' - group by string_id, client.name - having max(last_visit) > now() - interval '2 week' - order by string_id, client.name - """ - ) - - cols = [ - "Realm", - "Client", - "Hits", - "Last time", - ] - - pages.append(get_page(query, cols, title)) - - ### - - title = "Integrations by realm" - - query = SQL( - """ - select - realm.string_id, - case - when query like '%%external%%' then split_part(query, '/', 5) - else client.name - end client_name, - sum(count) as hits, - max(last_visit) as last_time - from zerver_useractivity ua - join zerver_client client on client.id = ua.client_id - join zerver_userprofile up on up.id = ua.user_profile_id - join zerver_realm realm on realm.id = up.realm_id - where - (query in ('send_message_backend', '/api/v1/send_message') - and client.name not in ('Android', 'ZulipiOS') - and client.name not like 'test: Zulip%%' - ) - or - query like '%%external%%' - group by string_id, client_name - having max(last_visit) > now() - interval '2 week' - order by string_id, client_name - """ - ) - - cols = [ - "Realm", - "Client", - "Hits", - "Last time", - ] - - pages.append(get_page(query, cols, title)) - - return pages - - @require_server_admin @has_request_variables def get_installation_activity(request: HttpRequest) -> HttpResponse: @@ -474,7 +361,6 @@ def get_installation_activity(request: HttpRequest) -> HttpResponse: data = [ ("Counts", counts_content), ("Durations", duration_content), - *((page["title"], page["content"]) for page in ad_hoc_queries()), ] title = "Activity"