##// END OF EJS Templates
settings: re-use attached request global config for performance...
bart -
r4200:007322e6 stable
parent child Browse files
Show More
@@ -288,7 +288,7 b' def attach_context_attributes(context, r'
288 288 """
289 289 config = request.registry.settings
290 290
291 rc_config = SettingsModel().get_all_settings(cache=True)
291 rc_config = SettingsModel().get_all_settings(cache=True, from_request=False)
292 292 context.rc_config = rc_config
293 293 context.rhodecode_version = rhodecode.__version__
294 294 context.rhodecode_edition = config.get('rhodecode.edition')
@@ -24,6 +24,7 b' import logging'
24 24 from collections import namedtuple
25 25 from functools import wraps
26 26 import bleach
27 from pyramid.threadlocal import get_current_request
27 28
28 29 from rhodecode.lib import rc_cache
29 30 from rhodecode.lib.utils2 import (
@@ -210,7 +211,21 b' class SettingsModel(BaseModel):'
210 211 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
211 212 CacheKey.set_invalidate(invalidation_namespace)
212 213
213 def get_all_settings(self, cache=False):
214 def get_all_settings(self, cache=False, from_request=True):
215 # defines if we use GLOBAL, or PER_REPO
216 repo = self._get_repo(self.repo) if self.repo else None
217 key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app"
218
219 # initially try the requests context, this is the fastest
220 # we only fetch global config
221 if from_request:
222 request = get_current_request()
223
224 if request and not repo and hasattr(request, 'call_context') and hasattr(request.call_context, 'rc_config'):
225 rc_config = request.call_context.rc_config
226 if rc_config:
227 return rc_config
228
214 229 region = rc_cache.get_or_create_region('sql_cache_short')
215 230 invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE
216 231
@@ -226,9 +241,6 b' class SettingsModel(BaseModel):'
226 241 }
227 242 return settings
228 243
229 repo = self._get_repo(self.repo) if self.repo else None
230 key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app"
231
232 244 inv_context_manager = rc_cache.InvalidationContext(
233 245 uid='cache_settings', invalidation_namespace=invalidation_namespace)
234 246 with inv_context_manager as invalidation_context:
General Comments 0
You need to be logged in to leave comments. Login now