#16773: QuerySet.count does no caching until the result cache is filled
------------------------+----------------------------------------------
 Reporter:  eternicode  |          Owner:  nobody
     Type:  Bug         |         Status:  new
Milestone:              |      Component:  Database layer (models, ORM)
  Version:  1.3         |       Severity:  Normal
 Keywords:              |   Triage Stage:  Unreviewed
Has patch:  0           |  Easy pickings:  0
    UI/UX:  0           |
------------------------+----------------------------------------------
 Before a queryset is evaluated, each QuerySet.count call for a given
 QuerySet hits the database with a `COUNT(*)` query, and doesn't cache the
 result in any way.

 {{{
 In [1]: from django.contrib.auth.models import User

 In [2]: from django.db import connections

 In [3]: qs = User.objects.all()

 In [4]: qs.count()
 Out[4]: 3

 In [5]: qs.count()
 Out[5]: 3

 In [6]: list(qs);

 In [7]: qs.count()
 Out[7]: 3

 In [8]: connections['default'].queries
 Out[8]:
 [{'sql': 'SELECT COUNT(*) FROM "auth_user"', 'time': '0.005'},
  {'sql': 'SELECT COUNT(*) FROM "auth_user"', 'time': '0.001'},
  {'sql': 'SELECT "auth_user"."id", "auth_user"."username",
 "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email",
 "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active",
 "auth_user"."is_superuser", "auth_user"."last_login",
 "auth_user"."date_joined" FROM "auth_user"',
   'time': '0.001'}]

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16773>
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