MCPcopy
hub / github.com/django/django / aiterator

Method aiterator

django/db/models/query.py:579–613  ·  view source on GitHub ↗

An asynchronous iterator over the results from applying this QuerySet to the database.

(self, chunk_size=2000)

Source from the content-addressed store, hash-verified

577 return self._iterator(use_chunked_fetch, chunk_size)
578
579 async def aiterator(self, chunk_size=2000):
580 """
581 An asynchronous iterator over the results from applying this QuerySet
582 to the database.
583 """
584 if chunk_size <= 0:
585 raise ValueError("Chunk size must be strictly positive.")
586 use_chunked_fetch = not connections[self.db].settings_dict.get(
587 "DISABLE_SERVER_SIDE_CURSORS"
588 )
589 iterable = self._iterable_class(
590 self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size
591 )
592 if self._prefetch_related_lookups:
593 results = []
594
595 async for item in iterable:
596 results.append(item)
597 if len(results) >= chunk_size:
598 await aprefetch_related_objects(
599 results, *self._prefetch_related_lookups
600 )
601 for result in results:
602 yield result
603 results.clear()
604
605 if results:
606 await aprefetch_related_objects(
607 results, *self._prefetch_related_lookups
608 )
609 for result in results:
610 yield result
611 else:
612 async for item in iterable:
613 yield item
614
615 def aggregate(self, *args, **kwargs):
616 """

Calls 4

getMethod · 0.45
appendMethod · 0.45
clearMethod · 0.45

Tested by 3

test_aiteratorMethod · 0.64