feat: ADRF async views (phase1) + native async serializers (phase2) + async cache infra
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from django.db.models import Q
|
||||
from rest_framework.views import APIView
|
||||
from adrf.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import status
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
@@ -27,7 +27,7 @@ class UserActivityView(APIView):
|
||||
],
|
||||
responses={200: success_response, 401: unauthorized_response},
|
||||
)
|
||||
def get(self, request):
|
||||
async def get(self, request):
|
||||
user = request.user
|
||||
page = int(request.query_params.get('page', 1))
|
||||
page_size = int(request.query_params.get('page_size', 20))
|
||||
@@ -36,7 +36,7 @@ class UserActivityView(APIView):
|
||||
|
||||
# 文章活动
|
||||
articles = Article.objects.filter(author=user, status='published').order_by('-created_at')[:50]
|
||||
for article in articles:
|
||||
async for article in articles:
|
||||
activities.append({
|
||||
'id': f'article_{article.id}',
|
||||
'type': 'article',
|
||||
@@ -50,7 +50,7 @@ class UserActivityView(APIView):
|
||||
|
||||
# 收藏活动
|
||||
favorites = CourseFavorite.objects.filter(user=user).select_related('course').order_by('-created_at')[:50]
|
||||
for fav in favorites:
|
||||
async for fav in favorites:
|
||||
activities.append({
|
||||
'id': f'favorite_{fav.id}',
|
||||
'type': 'favorite',
|
||||
@@ -64,7 +64,7 @@ class UserActivityView(APIView):
|
||||
|
||||
# 学习进度
|
||||
reads = ChapterRead.objects.filter(user=user, completed=True).select_related('chapter', 'course').order_by('-completed_at')[:50]
|
||||
for read in reads:
|
||||
async for read in reads:
|
||||
activities.append({
|
||||
'id': f'study_{read.id}',
|
||||
'type': 'study',
|
||||
|
||||
Reference in New Issue
Block a user