I'm trying to build an app with django. When I work with a small database (around 10k rows), the app works perfectly. However, in some views, I need to calculate some data of my classes, so I need to call all of my database. It is very slow (more than 30s), and according to Django Debug Toolbar, most part of the time is consumed by CPU.
Here's an example of a (very) simplified code I try to launch:
def test_view(request):
queryset_articles = Articles.objects.all()
total_count = sum([a.words_count for a in queryset_articles])
response = 'Total words : ' + str(count)
return HttpResponse(response)
How should I do to get a reasonable waiting time? I think about doing another table, which I would update frequently with these historical stats, then call them directly in my view.
Thank you,
Pierre