Opened 12 years ago
Last modified 11 years ago
#19949 closed Cleanup/optimization
Cached template loader doesn't cache TemplateDoesNotExist — at Initial Version
Reported by: | German M. Bravo | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.5 |
Severity: | Normal | Keywords: | templates cache |
Cc: | German M. Bravo | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In cases where multiple fallback templates are requested to the template loader (i.e. django.template.loader.select_template()
) to find the first one available, the cached template loader does not cache non-existent templates, making cached loader "slow" again if every time it has to try looking for a template that's been already found to be missing.
from django.template.loader import render_to_string
render_to_string(['missing_template_1.html', 'missing_template_2.html', ..., 'missing_template_N.html', 'existent_template.html'])
When using django.template.loaders.cached.Loader
, and given that snippet above, and the fact that missing_template_1.html
... missing_template_N.html
do not exist, the filesystem loader or other loaders get hit every time (trying and trying to find already known as missing templates).
I'm attaching a patch to fix this.