From 51542eb55e4d072d73d5203613267538dbf49964 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 6 Feb 2024 12:34:59 -0800 Subject: [PATCH] stats: Fix bad query plan for remote counts. We don't have an index on `(server_id, id)`, and in any case, we have a stronger guarantee that `remote_id` is time-sorted, from the construction of the analytics tables, than that the `id`s given these entries when uploaded are time-sorted. --- analytics/views/stats.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/analytics/views/stats.py b/analytics/views/stats.py index a12873bf55..c6a19f1ff6 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -384,11 +384,13 @@ def get_chart_data( _("No analytics data available. Please contact your server administrator.") ) if start is None: - first = aggregate_table_remote.objects.filter(server=server).first() + first = ( + aggregate_table_remote.objects.filter(server=server).order_by("remote_id").first() + ) assert first is not None start = first.end_time if end is None: - last = aggregate_table_remote.objects.filter(server=server).last() + last = aggregate_table_remote.objects.filter(server=server).order_by("remote_id").last() assert last is not None end = last.end_time else: