feat: ADRF async views (phase1) + native async serializers (phase2) + async cache infra
This commit is contained in:
+11
-11
@@ -1,4 +1,4 @@
|
||||
from rest_framework.views import APIView
|
||||
from adrf.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import status
|
||||
|
||||
@@ -24,7 +24,7 @@ class MyFavoritesView(APIView):
|
||||
],
|
||||
responses={200: success_response, 401: unauthorized_response},
|
||||
)
|
||||
def get(self, request):
|
||||
async def get(self, request):
|
||||
content_type = request.query_params.get('type', 'all')
|
||||
results = []
|
||||
|
||||
@@ -32,7 +32,7 @@ class MyFavoritesView(APIView):
|
||||
tool_favs = ToolFavorite.objects.filter(
|
||||
user=request.user
|
||||
).select_related('tool', 'tool__category').order_by('-created_at')
|
||||
for tf in tool_favs:
|
||||
async for tf in tool_favs:
|
||||
results.append({
|
||||
'id': tf.tool.id,
|
||||
'type': 'tool',
|
||||
@@ -49,7 +49,7 @@ class MyFavoritesView(APIView):
|
||||
article_favs = ArticleFavorite.objects.filter(
|
||||
user=request.user
|
||||
).select_related('article', 'article__author').order_by('-created_at')
|
||||
for af in article_favs:
|
||||
async for af in article_favs:
|
||||
results.append({
|
||||
'id': af.article.id,
|
||||
'type': 'article',
|
||||
@@ -69,7 +69,7 @@ class MyFavoritesView(APIView):
|
||||
course_favs = CourseFavorite.objects.filter(
|
||||
user=request.user
|
||||
).select_related('course', 'course__author').order_by('-created_at')
|
||||
for cf in course_favs:
|
||||
async for cf in course_favs:
|
||||
results.append({
|
||||
'id': cf.course.id,
|
||||
'type': 'course',
|
||||
@@ -79,7 +79,7 @@ class MyFavoritesView(APIView):
|
||||
'level': cf.course.level,
|
||||
'icon_name': getattr(cf.course, 'icon_name', ''),
|
||||
'color': getattr(cf.course, 'color', ''),
|
||||
'chapters_count': cf.course.chapters.count() if hasattr(cf.course, 'chapters') else 0,
|
||||
'chapters_count': await cf.course.chapters.acount() if hasattr(cf.course, 'chapters') else 0,
|
||||
'author': getattr(cf.course.author, 'nickname', '') if cf.course.author else '',
|
||||
'author_id': cf.course.author_id,
|
||||
'created_at': cf.created_at.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
@@ -89,7 +89,7 @@ class MyFavoritesView(APIView):
|
||||
api_favs = ApiFavorite.objects.filter(
|
||||
user=request.user
|
||||
).select_related('api_item').order_by('-created_at')
|
||||
for af in api_favs:
|
||||
async for af in api_favs:
|
||||
results.append({
|
||||
'id': af.api_item.id,
|
||||
'type': 'api',
|
||||
@@ -104,10 +104,10 @@ class MyFavoritesView(APIView):
|
||||
|
||||
counts = {
|
||||
'total': len(results),
|
||||
'tool': ToolFavorite.objects.filter(user=request.user).count(),
|
||||
'article': ArticleFavorite.objects.filter(user=request.user).count(),
|
||||
'course': CourseFavorite.objects.filter(user=request.user).count(),
|
||||
'api': ApiFavorite.objects.filter(user=request.user).count(),
|
||||
'tool': await ToolFavorite.objects.filter(user=request.user).acount(),
|
||||
'article': await ArticleFavorite.objects.filter(user=request.user).acount(),
|
||||
'course': await CourseFavorite.objects.filter(user=request.user).acount(),
|
||||
'api': await ApiFavorite.objects.filter(user=request.user).acount(),
|
||||
}
|
||||
|
||||
return create_standardized_response(
|
||||
|
||||
Reference in New Issue
Block a user