@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from django.core.cache import cache
|
||||
@@ -25,6 +26,9 @@ from .models import Notification
|
||||
from .serializers import NotificationSerializer
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def project_stage_label(project):
|
||||
return {
|
||||
"script": "Stage 1 · 脚本",
|
||||
@@ -288,7 +292,13 @@ class NotificationViewSet(TeamScopedViewSetMixin, ModelViewSet):
|
||||
if not Notification.objects.filter(team=team).exists():
|
||||
ensure_team_notifications(team, request.user)
|
||||
return
|
||||
if cache.add(f"ops:notif-refresh:{team.id}", 1, timeout=60):
|
||||
# 通知列表是普通读接口;Redis 不可用时跳过后台刷新,不能因此返回 500。
|
||||
try:
|
||||
should_refresh = cache.add(f"ops:notif-refresh:{team.id}", 1, timeout=60)
|
||||
except Exception:
|
||||
logger.warning("通知刷新缓存不可用,跳过本次后台刷新", exc_info=True)
|
||||
should_refresh = False
|
||||
if should_refresh:
|
||||
from .tasks import ensure_team_notifications_task
|
||||
|
||||
user_id = str(request.user.id) if getattr(request.user, "id", None) else None
|
||||
|
||||
Reference in New Issue
Block a user