#16773: QuerySet.count does no caching until the result cache is filled
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  eternicode                         |         Status:  new
                   Type:  Bug        |      Component:  Database layer
              Milestone:             |  (models, ORM)
                Version:  1.3        |       Severity:  Normal
             Resolution:             |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |    Needs tests:  0
    Needs documentation:  0          |  Easy pickings:  0
Patch needs improvement:  0          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
Changes (by tarequeh):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 Currently call to count stops hitting DB once the queryset is cached. If a
 cache for count is introduced, count will stop hitting DB upon on a call
 to count. And that may happen before queryset get evaluated/cached.
 Afterwards when queryset is evaluated, it might have number of results
 different than the cached count depending on how many objects were created
 between the call to count and evaluation. So codes like this won't be
 valid anymore:

 {{{
 #!div style="font-size: 80%"
   {{{#!python
   books = Book.objects.all()
   print books.count() # say prints 5
   Book.objects.create(title='Game of Thrones')
   print books.count() # currently prints 6 but with cache will print 5
   }}}
 }}}

 But if the queryset is fully cached, then calling .count doesn't invoke
 further count calls:

 {{{
 #!div style="font-size: 80%"
   {{{#!python
   books = Book.objects.all()
   print books.count() # say prints 5
   print [x.__dict__ for x in books]
   Book.objects.create(title='Game of Thrones')
   print books.count() # prints 5
   }}}
 }}}

 So caching count is probably not a good idea.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16773#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to