﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16773	QuerySet.count does no caching until the result cache is filled	eternicode	nobody	"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'}]

}}}
"	Bug	closed	Database layer (models, ORM)	1.3	Normal	wontfix			Design decision needed	0	0	0	0	0	0
