Perform a SELECT COUNT() and return the number of records as an integer. If the QuerySet is already fully cached, return the length of the cached results set to avoid multiple SELECT COUNT(*) calls.
(self)
| 641 | return await sync_to_async(self.aggregate)(*args, **kwargs) |
| 642 | |
| 643 | def count(self): |
| 644 | """ |
| 645 | Perform a SELECT COUNT() and return the number of records as an |
| 646 | integer. |
| 647 | |
| 648 | If the QuerySet is already fully cached, return the length of the |
| 649 | cached results set to avoid multiple SELECT COUNT(*) calls. |
| 650 | """ |
| 651 | if self._result_cache is not None: |
| 652 | return len(self._result_cache) |
| 653 | |
| 654 | return self.query.get_count(using=self.db) |
| 655 | |
| 656 | async def acount(self): |
| 657 | return await sync_to_async(self.count)() |