refactor: replace sync_to_async queryset slice with async for comprehension
This commit is contained in:
@@ -215,9 +215,12 @@ class AsyncAPIView(APIView):
|
|||||||
offset = 0
|
offset = 0
|
||||||
if offset < 0:
|
if offset < 0:
|
||||||
offset = 0
|
offset = 0
|
||||||
|
async def _slice():
|
||||||
|
return [item async for item in query_set[offset:offset + limit]]
|
||||||
|
|
||||||
count, results = await asyncio.gather(
|
count, results = await asyncio.gather(
|
||||||
query_set.acount(),
|
query_set.acount(),
|
||||||
sync_to_async(lambda: list(query_set[offset:offset + limit]), thread_sensitive=True)(),
|
_slice(),
|
||||||
)
|
)
|
||||||
if object_serializer:
|
if object_serializer:
|
||||||
results = await self.async_serialize_data(
|
results = await self.async_serialize_data(
|
||||||
|
|||||||
Reference in New Issue
Block a user