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:
Jacob Kaplan-Moss 2007-02-23 20:58:28 +00:00
parent ee5415e3dd
commit 16bd0aa991
1 changed files with 11 additions and 1 deletions

View File

@ -194,7 +194,17 @@ class QuerySet(object):
yield obj
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._order_by = ()
counter._select_related = False