refactor: replace sync_to_async queryset slice with async for comprehension

This commit is contained in:
2026-05-26 21:42:43 -06:00
parent c49a6af066
commit e47923758e

View File

@@ -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(