feat: 100% async - native async serializers (adata/asave/acreate), async cache (redis.asyncio), view call-site migration

This commit is contained in:
async-upgrade
2026-09-06 14:36:41 +08:00
parent 8f488fcaaa
commit 571641e539
18 changed files with 81 additions and 81 deletions
+7 -7
View File
@@ -44,7 +44,7 @@ class BugReportListCreateAPIView(generics.ListCreateAPIView):
items = [x async for x in queryset]
serializer = self.get_serializer(items, many=True)
# 兜底:user_name 触发 user 外键懒加载、images_count 内部有同步 ORM count()
data = await sync_to_async(lambda: serializer.data)()
data = await serializer.adata
return create_standardized_response(
code=ResponseCode.SUCCESS,
data=data,
@@ -60,13 +60,13 @@ class BugReportListCreateAPIView(generics.ListCreateAPIView):
)
async def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
is_valid = await sync_to_async(serializer.is_valid)()
is_valid = serializer.is_valid()
if is_valid:
# 兜底:serializer.create 内部有同步 ORM(BugReport/BugReportImage/BugReportAttachment 的 create)
bug_report = await sync_to_async(serializer.save)(user=request.user)
bug_report = await serializer.asave(user=request.user)
detail_serializer = BugReportDetailSerializer(bug_report)
# 兜底:detail 序列化会触发 user/images/attachments/comments 的同步懒加载
data = await sync_to_async(lambda: detail_serializer.data)()
data = await detail_serializer.adata
return create_standardized_response(
code=ResponseCode.SUCCESS,
data=data,
@@ -104,7 +104,7 @@ class BugReportDetailAPIView(generics.RetrieveAPIView):
instance = await self.get_object()
serializer = self.get_serializer(instance)
# 兜底:detail 序列化会触发 user/images/attachments/comments 的同步懒加载
data = await sync_to_async(lambda: serializer.data)()
data = await serializer.adata
return create_standardized_response(
code=ResponseCode.SUCCESS,
data=data,
@@ -144,7 +144,7 @@ class BugReportCommentCreateAPIView(generics.CreateAPIView):
)
serializer = self.get_serializer(data=request.data)
is_valid = await sync_to_async(serializer.is_valid)()
is_valid = serializer.is_valid()
if is_valid:
# 兜底:serializer.create 内部有同步 ORM(comment 及其图片/附件的 create)
comment = await sync_to_async(serializer.save)(
@@ -154,7 +154,7 @@ class BugReportCommentCreateAPIView(generics.CreateAPIView):
)
comment_serializer = BugReportCommentSerializer(comment)
# 兜底:comment 序列化会触发 user 外键与 images/attachments 的同步懒加载
data = await sync_to_async(lambda: comment_serializer.data)()
data = await comment_serializer.adata
return create_standardized_response(
code=ResponseCode.SUCCESS,
data=data,