From 0b93814261f136dc70bb265ea0e76b36a0c0b680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Tue, 15 Sep 2026 15:06:21 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20dashboard=20=E7=A1=AE=E5=AE=9A?= =?UTF-8?q?=E6=80=A7=E6=8E=92=E5=BA=8F=E4=B8=8E=E6=B3=A8=E9=87=8A=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sources/top_pages Top8 加平局次序键(referrer_domain/path), 平局时跨请求顺序稳定 - test_dashboard 修正过时注释(b 站数据同为 refresh_daily 真实落行) pytest 79 passed 无回归。 Co-Authored-By: Claude Code --- server/tracker/api/dashboard.py | 6 ++++-- server/tracker/tests/test_dashboard.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/tracker/api/dashboard.py b/server/tracker/api/dashboard.py index c87a9dd..4e14550 100644 --- a/server/tracker/api/dashboard.py +++ b/server/tracker/api/dashboard.py @@ -72,7 +72,8 @@ class OverviewView(EnvelopeMixin, APIView): q = q.filter(site=site) return [{"source": r["referrer_domain"] or "直接访问", "sessions": r["n"]} for r in q.values("referrer_domain") - .annotate(n=Count("id")).order_by("-n")[:8]] + .annotate(n=Count("id")) + .order_by("-n", "referrer_domain")[:8]] # 平局时次序跨请求稳定 def _today_pages(self, site, today): start, end = _day_bounds(today) @@ -82,4 +83,5 @@ class OverviewView(EnvelopeMixin, APIView): q = q.filter(site=site) return [{"path": r["path"], "pv": r["n"]} for r in q.values("path") - .annotate(n=Count("id")).order_by("-n")[:8]] + .annotate(n=Count("id")) + .order_by("-n", "path")[:8]] # 平局时次序跨请求稳定 diff --git a/server/tracker/tests/test_dashboard.py b/server/tracker/tests/test_dashboard.py index 69758f8..d16d642 100644 --- a/server/tracker/tests/test_dashboard.py +++ b/server/tracker/tests/test_dashboard.py @@ -92,7 +92,7 @@ def test_overview_trend_uses_dailystat_history(client, member_user): sa = _session(site_a, va, "sa", at=yn) _events(site_a, va, sa, 3, "/", at=yn, prefix="ya") refresh_daily(site_a, YESTERDAY) - # b 站昨天直接落一行(site=None 时验证 Sum 跨站点聚合) + # b 站昨天 4 事件同样走 refresh_daily——两站各落一行,验证 site=None 的跨站 Sum vb = Visitor.objects.create(site=site_b, visitor_id="vb") sb = _session(site_b, vb, "sb", at=yn) _events(site_b, vb, sb, 4, "/", at=yn, prefix="yb")