Ticket #3541: cache_count.patch
File cache_count.patch, 1.0 KB (added by , 18 years ago) |
---|
-
django/db/models/query.py
194 194 yield obj 195 195 196 196 def count(self): 197 "Performs a SELECT COUNT() and returns the number of records as an integer." 197 """ 198 Returns the number of records as an integer. 199 200 If _result_cache has been loaded, do len(self._result_cache) 201 otherwise perform a SELECT COUNT(). 202 """ 203 if hasattr(self, '_result_count'): 204 return self._result_count 205 if self._result_cache is not None: 206 self._result_count = len(self._result_cache) 207 return self._result_count 198 208 counter = self._clone() 199 209 counter._order_by = () 200 210 counter._select_related = False … … 225 235 if limit: 226 236 count = min(limit, count) 227 237 238 self._result_count = count 228 239 return count 229 240 230 241 def get(self, *args, **kwargs):