mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
counts: Add function compute_max_monthly_messages for remote servers.
This calculates the largest amount of messages sent within a month for the last 3 months. The query is targeted for the specific use-case in this function - for finding the count for a specific server. For calculating this in bulk for a large number of remote server an adapted, bulk query will be needed - rather than running this one in a loop, which would likely be very inefficient.
This commit is contained in:
committed by
Tim Abbott
parent
617d2d509c
commit
3cafdbdc1e
@@ -3,7 +3,7 @@ from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
from typing import Any, Dict, Iterable, List, Optional
|
||||
from typing import Any, Dict, Iterable, List, Optional, Union
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from django.conf import settings
|
||||
@@ -47,8 +47,10 @@ from zerver.models import (
|
||||
get_user_profile_by_id,
|
||||
)
|
||||
from zerver.views.invite import get_invitee_emails_set
|
||||
from zilencer.lib.remote_counts import MissingDataError
|
||||
|
||||
if settings.ZILENCER_ENABLED:
|
||||
from zilencer.lib.remote_counts import compute_max_monthly_messages
|
||||
from zilencer.models import RemoteZulipServer
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
@@ -444,10 +446,20 @@ def remote_servers_support(
|
||||
remote_servers = get_remote_servers_for_support(
|
||||
email_to_search=email_to_search, hostname_to_search=hostname_to_search
|
||||
)
|
||||
remote_server_to_max_monthly_messages: Dict[int, Union[int, str]] = dict()
|
||||
for remote_server in remote_servers:
|
||||
try:
|
||||
remote_server_to_max_monthly_messages[remote_server.id] = compute_max_monthly_messages(
|
||||
remote_server
|
||||
)
|
||||
except MissingDataError:
|
||||
remote_server_to_max_monthly_messages[remote_server.id] = "Recent data missing"
|
||||
|
||||
return render(
|
||||
request,
|
||||
"analytics/remote_server_support.html",
|
||||
context=dict(
|
||||
remote_servers=remote_servers,
|
||||
remote_server_to_max_monthly_messages=remote_server_to_max_monthly_messages,
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user