22 lines
906 B
Python
22 lines
906 B
Python
from django.contrib.auth import get_user_model
|
|
|
|
from airshelf.celery import app
|
|
from apps.accounts.models import Team
|
|
|
|
|
|
@app.task(queue="airshelf.quick")
|
|
def ensure_team_notifications_task(team_id: str, user_id: str | None = None) -> None:
|
|
"""后台生成/补齐团队站内通知。
|
|
|
|
原先在 NotificationViewSet.list() 里同步执行:每次刷新都要读计费账本 +
|
|
对项目/资产/扣费流水逐条 get_or_create,几十次 DB 往返压在请求线程上,拖慢通知接口。
|
|
现改由 Celery 异步执行,请求只负责读现有通知,生成搬到后台 worker。
|
|
"""
|
|
from apps.ops.views import ensure_team_notifications # 延迟导入避免循环依赖
|
|
|
|
team = Team.objects.filter(id=team_id).first()
|
|
if team is None:
|
|
return
|
|
user = get_user_model().objects.filter(id=user_id).first() if user_id else None
|
|
ensure_team_notifications(team, user)
|