mirror of
https://github.com/django/django.git
synced 2025-04-01 03:56:42 +00:00
Fixed #3541: queryset.count() now respects the queryset cache.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4561 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ee5415e3dd
commit
16bd0aa991
@ -194,7 +194,17 @@ class QuerySet(object):
|
|||||||
yield obj
|
yield obj
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
"Performs a SELECT COUNT() and returns the number of records as an integer."
|
"""
|
||||||
|
Performs a SELECT COUNT() and returns the number of records as an
|
||||||
|
integer.
|
||||||
|
|
||||||
|
If the queryset is already cached (i.e. self._result_cache is set) this
|
||||||
|
simply returns the length of the cached results set to avoid multiple
|
||||||
|
SELECT COUNT(*) calls.
|
||||||
|
"""
|
||||||
|
if self._results_cache is not None:
|
||||||
|
return len(self._results_cache)
|
||||||
|
|
||||||
counter = self._clone()
|
counter = self._clone()
|
||||||
counter._order_by = ()
|
counter._order_by = ()
|
||||||
counter._select_related = False
|
counter._select_related = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user