mirror of https://github.com/pallets/flask.git
				
				
				
			Merge pull request #1814 from pallets/feature/faster-template-loading
Fast path for disabled template load explain.
This commit is contained in:
		
						commit
						87787b130b
					
				|  | @ -52,27 +52,36 @@ class DispatchingJinjaLoader(BaseLoader): | ||||||
|         self.app = app |         self.app = app | ||||||
| 
 | 
 | ||||||
|     def get_source(self, environment, template): |     def get_source(self, environment, template): | ||||||
|         explain = self.app.config['EXPLAIN_TEMPLATE_LOADING'] |         if self.app.config['EXPLAIN_TEMPLATE_LOADING']: | ||||||
|  |             return self._get_source_explained(environment, template) | ||||||
|  |         return self._get_source_fast(environment, template) | ||||||
|  | 
 | ||||||
|  |     def _get_source_explained(self, environment, template): | ||||||
|         attempts = [] |         attempts = [] | ||||||
|         tmplrv = None |         trv = None | ||||||
| 
 | 
 | ||||||
|         for srcobj, loader in self._iter_loaders(template): |         for srcobj, loader in self._iter_loaders(template): | ||||||
|             try: |             try: | ||||||
|                 rv = loader.get_source(environment, template) |                 rv = loader.get_source(environment, template) | ||||||
|                 if tmplrv is None: |                 if trv is None: | ||||||
|                     tmplrv = rv |                     trv = rv | ||||||
|                 if not explain: |  | ||||||
|                     break |  | ||||||
|             except TemplateNotFound: |             except TemplateNotFound: | ||||||
|                 rv = None |                 rv = None | ||||||
|             attempts.append((loader, srcobj, rv)) |             attempts.append((loader, srcobj, rv)) | ||||||
| 
 | 
 | ||||||
|         if explain: |         from .debughelpers import explain_template_loading_attempts | ||||||
|             from .debughelpers import explain_template_loading_attempts |         explain_template_loading_attempts(self.app, template, attempts) | ||||||
|             explain_template_loading_attempts(self.app, template, attempts) |  | ||||||
| 
 | 
 | ||||||
|         if tmplrv is not None: |         if trv is not None: | ||||||
|             return tmplrv |             return trv | ||||||
|  |         raise TemplateNotFound(template) | ||||||
|  | 
 | ||||||
|  |     def _get_source_fast(self, environment, template): | ||||||
|  |         for srcobj, loader in self._iter_loaders(template): | ||||||
|  |             try: | ||||||
|  |                 return loader.get_source(environment, template) | ||||||
|  |             except TemplateNotFound: | ||||||
|  |                 continue | ||||||
|         raise TemplateNotFound(template) |         raise TemplateNotFound(template) | ||||||
| 
 | 
 | ||||||
|     def _iter_loaders(self, template): |     def _iter_loaders(self, template): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue