Ticket #3541: faster_count.patch

File faster_count.patch, 764 bytes (added by Chris Beaven, 18 years ago)
  • django/db/models/query.py

     
    194194                yield obj
    195195
    196196    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 self._result_cache is not None:
     204            return len(self._result_cache)
     205       
    198206        counter = self._clone()
    199207        counter._order_by = ()
    200208        counter._select_related = False
Back to Top