Observed Behavior
Calculating and displaying the copyright notice for a page makes repeated queries to the SiteVars table, both in the template tags and in the models (MediaObject and AbstractOpenGraph).
The get_template_names and get_context_data methods of the views also make repeated SiteVar queries to look up template names.
In list views, the pagination methods make separate queries for site pagination defaults.
Expected Behavior
SiteVars should be cached and the table should be accessed no more than once per request.
Probably the "get_value" should be either removed entirely to prevent temptation, or modified so that it makes no database queries but only accesses the cached values.
It might be convenient if site.vars was subscriptable, allowing you to access a site var as site.vars["base_template"]. Again, this should access the cache and not produce a database query. Unfortunately that would interfere with Django's default queryset slicing. Best not to change Django's default behavior, that would be confusing for users.
Observed Behavior
Calculating and displaying the copyright notice for a page makes repeated queries to the SiteVars table, both in the template tags and in the models (MediaObject and AbstractOpenGraph).
The
get_template_namesandget_context_datamethods of the views also make repeated SiteVar queries to look up template names.In list views, the pagination methods make separate queries for site pagination defaults.
Expected Behavior
SiteVars should be cached and the table should be accessed no more than once per request.
Probably the "get_value" should be either removed entirely to prevent temptation, or modified so that it makes no database queries but only accesses the cached values.
It might be convenient ifUnfortunately that would interfere with Django's default queryset slicing. Best not to change Django's default behavior, that would be confusing for users.site.varswas subscriptable, allowing you to access a site var assite.vars["base_template"]. Again, this should access the cache and not produce a database query.