In one of my views for the staff, I show the last 10 registrars on my site and some of their activity like so:
recentlyjoined = User.objects.order_by('-date_joined').annotate(post_count=Count('post', distinct=True),
text_count=Count('text', distinct=True),
pdf_count=Count('pdf', distinct=True),
discussion_count=Count('discussion', distinct=True))[0:10]
And in my template I do
{% for applicant in recentlyjoined %}
{{ applicant.post_count }}
{% endfor %}
for all the annotations above.
When I call this site, it takes VERY long to load, sometimes I even get a timeout error. I narrowed it down to this annotations. Whats wrong? Why does this improve so bad? And how can I fix it?
(And in case it matters: In my sandbox database I have only 15 users, but one of them has like 5000 posts. So its not exactly big data to handle.)