Open tbrlpld opened 1 year ago
@tbrlpld let's break this down into logically smaller tickets to tackle this work
@mtdenton I have turned this into an epic. I think best way to tackle this might be to go on a file by file basis, because I don't think there is a way to address them all at once and the solutions might need to be specific based on the use case in each template.
The basic strategy (move logic to Python get_context
or other method) is outlined in the epic and in each issue.
It may be valuable (but not necessarily required) to tackle #8813 before, or as part of, this epic.
This also feels related to #9812
Per @jhonatan-lopes recommendation, this issue needs to be addressed soon as it is currently a major source of performance degradation. Updated priority from P2 to P1.
Description
We are calling the
.localized
property on translatable objects (provided by theTranslatableMixin
) in template code quite a bit:I recently noticed that
.localized
is not a cached property. That means, that each access might trigger another database query (considering that the locale needs to be retrieved, it might be even more).Instead of relying on the template code to pull the localized versions of content, we should make sure that the pages and view code provides the properly localized items to the templates (e.g. via
get_context
or other methods).Reducing the database queries that our template code causes should improve the pages performance. When this is done in widely used fragments, it might give a performance boost to the entire site.
See also:
Acceptance criteria
It is hard to specify at this point what we exactly expect, but we should be reducing the number of locations where
.localized
is used in templates..localized
in template code is reduced.┆Issue is synchronized with this Jira Epic