From e47923758ebd549adae4d15cb04d7b4752a17469 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 26 May 2026 21:42:43 -0600 Subject: [PATCH] refactor: replace sync_to_async queryset slice with async for comprehension --- utils/api/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/api/api.py b/utils/api/api.py index 4c95f6d..2d610be 100644 --- a/utils/api/api.py +++ b/utils/api/api.py @@ -215,9 +215,12 @@ class AsyncAPIView(APIView): offset = 0 if offset < 0: offset = 0 + async def _slice(): + return [item async for item in query_set[offset:offset + limit]] + count, results = await asyncio.gather( query_set.acount(), - sync_to_async(lambda: list(query_set[offset:offset + limit]), thread_sensitive=True)(), + _slice(), ) if object_serializer: results = await self.async_serialize_data(