Reputation: 7301
I have created a Django app and everything seems to be working nicely. I then started looking at the Django debug toolbar and saw that some of my pages are generating over 100 queries, with a lot of duplicates. However, the page remains snappy and the execution time is still low due to caching I would imagine.
My question is, are these large number of queries a big problem? Should I make it a priority to get the number of queries down or is it fine if I call the same query twice, knowing that the Django ORM will cache the result.
For instance, if I make the same query in a template a couple if times, should I pass it as a context variable or set it equal to a variable in the template using a with tag, instead of calling it multiple times, even though Django caches the result?
Upvotes: 0
Views: 346
Reputation: 43300
The number of queries does not matter, its the data they're getting and the time they're taking that you need to be concerned with.
If anything spend minimal time looking at the queries that take the longest amount of time to finish since these will be returning the most data, and look at if you really need all of this data. If you do, is there another way you can access it. If you don't can you reduce the data being returned.
As always, if performance is not an issue, there is no need to worry about it, concentrate on other things that may be bottlenecks.
Upvotes: 1