Re:The Practical Guide to Scaling Django
by nprateem on Saturday November 16, 2024 @06:25AM
(#42155864)
It'd be faster to retrieve from a cache than to make a round-trip to a DB to get the data needed for templating.
Re:The Practical Guide to Scaling Django
by telgareith on Saturday November 16, 2024 @08:44AM
(#42156365)
[assumption]
Re:The Practical Guide to Scaling Django
by danpalmer on Saturday November 16, 2024 @07:55PM
(#42161011)
My point was that you shouldn't be doing DB queries in the template. If you're doing the DB queries before templating then you should also be doing the cache queries before templating too.
I haven't used it, but I think this is well targeted by https://github.com/dabapps/django-zen-queries.
The only place it's possible worth it is if you do a lot of database queries from your template rendering, and you're therefore caching database results (as rendered text). In that case, it's an easy patch. However a much better solution is to fetch all database results up front.
In my previous company we had a very significant Django codebase with plenty of templating, and found that using the templating system for (lazy loaded) database queries or caching was more hassle than it was worth and avoided it as much as possible. Treating template rendering as a pure CPU bound function was always better.