feat: ADRF async views (phase1) + native async serializers (phase2) + async cache infra

This commit is contained in:
async-upgrade
2026-09-06 14:26:17 +08:00
parent 9a6577f71e
commit 8f488fcaaa
55 changed files with 2224 additions and 1513 deletions
+8 -8
View File
@@ -1,4 +1,4 @@
from rest_framework.views import APIView
from adrf.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from user.models import Invitation, FUser
@@ -16,12 +16,12 @@ class InviteCodeAPIView(APIView):
operation_description='获取当前用户的邀请码和邀请链接',
responses={200: success_response, 401: unauthorized_response},
)
def get(self, request):
async def get(self, request):
user = request.user
# Generate or get existing invite code
invite_code = f"CY{str(user.id).zfill(6)}"
# Ensure the invitation record exists
Invitation.objects.get_or_create(
await Invitation.objects.aget_or_create(
inviter=user,
invite_code=invite_code,
defaults={'is_used': False}
@@ -41,11 +41,11 @@ class InviteStatsAPIView(APIView):
operation_description='获取当前用户的邀请统计信息,包括已邀请人数、获得积分和待使用邀请数',
responses={200: success_response, 401: unauthorized_response},
)
def get(self, request):
async def get(self, request):
user = request.user
used_count = Invitation.objects.filter(inviter=user, is_used=True).count()
used_count = await Invitation.objects.filter(inviter=user, is_used=True).acount()
total_points = used_count * 500 # 500 points per invite
pending_count = Invitation.objects.filter(inviter=user, is_used=False).count()
pending_count = await Invitation.objects.filter(inviter=user, is_used=False).acount()
return Response({
'invited_count': used_count,
'total_points': total_points,
@@ -62,11 +62,11 @@ class InviteRecordsAPIView(APIView):
operation_description='获取当前用户的所有邀请记录列表',
responses={200: success_response, 401: unauthorized_response},
)
def get(self, request):
async def get(self, request):
user = request.user
records = Invitation.objects.filter(inviter=user).order_by('-created_at')
data = []
for r in records:
async for r in records:
data.append({
'id': r.id,
'invite_code': r.invite_code,