Skip to content
Myr

Merge pull request #1814 from pallets/feature/faster-template-loading

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fast path for disabled template load explain.

authored by Armin Ronacher · committed by Armin Ronacher · parents 21d595b, 96ec24f · Browse files · 1 file+20 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−11 removed

  • other:+20 added−11 removed

1 file+20 added−11 removed

modified:flask/templating.py+20 added-11 removed
50 unmodified lines
51 def __init__(self, app):52 self.app = app5354 def get_source(self, environment, template):55 explain = self.app.config['EXPLAIN_TEMPLATE_LOADING']55 if self.app.config['EXPLAIN_TEMPLATE_LOADING']:56 return self._get_source_explained(environment, template)57 return self._get_source_fast(environment, template)5859 def _get_source_explained(self, environment, template):60 attempts = []57 tmplrv = None61 trv = None6263 for srcobj, loader in self._iter_loaders(template):64 try:65 rv = loader.get_source(environment, template)62 if tmplrv is None:63 tmplrv = rv64 if not explain:65 break66 if trv is None:67 trv = rv68 except TemplateNotFound:69 rv = None70 attempts.append((loader, srcobj, rv))7170 if explain:71 from .debughelpers import explain_template_loading_attempts72 explain_template_loading_attempts(self.app, template, attempts)72 from .debughelpers import explain_template_loading_attempts73 explain_template_loading_attempts(self.app, template, attempts)7474 if tmplrv is not None:75 return tmplrv75 if trv is not None:76 return trv77 raise TemplateNotFound(template)7879 def _get_source_fast(self, environment, template):80 for srcobj, loader in self._iter_loaders(template):81 try:82 return loader.get_source(environment, template)83 except TemplateNotFound:84 continue85 raise TemplateNotFound(template)8687 def _iter_loaders(self, template):88 loader = self.app.jinja_loader89 if loader is not None:90 yield self.app, loader
59 unmodified lines