From ad95bea3019e9c9743b30d6fd4e96f2f5a9fd2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=8F=E6=B6=9B?= <1537080775@qq.com> Date: Thu, 26 Jun 2025 17:51:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(application):=20=E4=BF=AE=E5=A4=8D=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=88=B7=E6=8E=A5=E6=94=B6=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了对 user_id == 1 的特殊判断,统一了消息数量统计逻辑 - 优化了代码结构,提高了代码的可读性和维护性 --- backend/application/sse_views.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/application/sse_views.py b/backend/application/sse_views.py index c498630..f1cbe01 100644 --- a/backend/application/sse_views.py +++ b/backend/application/sse_views.py @@ -17,10 +17,7 @@ def event_stream(user_id): last_db_change_time = cache.get('last_db_change_time', 0) # 只有当数据库发生变化时才检查总数 if last_db_change_time and last_db_change_time > last_sent_time: - if user_id == 1: - count = MessageCenterTargetUser.objects.filter(is_read=False).count() - else: - count = MessageCenterTargetUser.objects.filter(users=user_id, is_read=False).count() + count = MessageCenterTargetUser.objects.filter(users=user_id, is_read=False).count() yield f"data: {count}\n\n" last_sent_time = time.time()