Show More
@@ -581,19 +581,24 b' def sanitize_settings_and_apply_defaults' | |||||
581 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') |
|
581 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') | |
582 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) |
|
582 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) | |
583 |
|
583 | |||
|
584 | # cache_general | |||
|
585 | settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace') | |||
|
586 | settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int') | |||
|
587 | settings_maker.make_setting('rc_cache.cache_general.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_general.db')) | |||
|
588 | ||||
584 | # cache_perms |
|
589 | # cache_perms | |
585 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') |
|
590 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') | |
586 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60, parser='int') |
|
591 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int') | |
587 | settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_perms.db')) |
|
592 | settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_perms.db')) | |
588 |
|
593 | |||
589 | # cache_repo |
|
594 | # cache_repo | |
590 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') |
|
595 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') | |
591 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60, parser='int') |
|
596 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int') | |
592 | settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_repo.db')) |
|
597 | settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_repo.db')) | |
593 |
|
598 | |||
594 | # cache_license |
|
599 | # cache_license | |
595 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') |
|
600 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') | |
596 |
settings_maker.make_setting('rc_cache.cache_license.expiration_time', 5 |
|
601 | settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int') | |
597 | settings_maker.make_setting('rc_cache.cache_license.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_license.db')) |
|
602 | settings_maker.make_setting('rc_cache.cache_license.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_license.db')) | |
598 |
|
603 | |||
599 | # cache_repo_longterm memory, 96H |
|
604 | # cache_repo_longterm memory, 96H |
@@ -31,6 +31,7 b' from rhodecode.lib import rc_cache' | |||||
31 | from rhodecode.lib.utils2 import ( |
|
31 | from rhodecode.lib.utils2 import ( | |
32 | Optional, AttributeDict, safe_str, remove_prefix, str2bool) |
|
32 | Optional, AttributeDict, safe_str, remove_prefix, str2bool) | |
33 | from rhodecode.lib.vcs.backends import base |
|
33 | from rhodecode.lib.vcs.backends import base | |
|
34 | from rhodecode.lib.statsd_client import StatsdClient | |||
34 | from rhodecode.model import BaseModel |
|
35 | from rhodecode.model import BaseModel | |
35 | from rhodecode.model.db import ( |
|
36 | from rhodecode.model.db import ( | |
36 | RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting, CacheKey) |
|
37 | RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting, CacheKey) | |
@@ -208,16 +209,28 b' class SettingsModel(BaseModel):' | |||||
208 | Session().add(res) |
|
209 | Session().add(res) | |
209 | return res |
|
210 | return res | |
210 |
|
211 | |||
|
212 | def get_cache_region(self): | |||
|
213 | repo = self._get_repo(self.repo) if self.repo else None | |||
|
214 | cache_key = "repo.{}".format(repo.repo_id) if repo else "general_settings" | |||
|
215 | cache_namespace_uid = 'cache_settings.{}'.format(cache_key) | |||
|
216 | region = rc_cache.get_or_create_region('cache_general', cache_namespace_uid) | |||
|
217 | return region, cache_key | |||
|
218 | ||||
211 | def invalidate_settings_cache(self): |
|
219 | def invalidate_settings_cache(self): | |
212 | invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE |
|
220 | from rhodecode.authentication.base import get_authn_registry | |
213 | CacheKey.set_invalidate(invalidation_namespace) |
|
221 | ||
|
222 | region, cache_key = self.get_cache_region() | |||
|
223 | log.debug('Invalidation cache region %s for cache_key: %s', region, cache_key) | |||
|
224 | region.invalidate() | |||
|
225 | registry = get_current_registry() | |||
|
226 | if registry: | |||
|
227 | authn_registry = get_authn_registry(registry) | |||
|
228 | if authn_registry: | |||
|
229 | authn_registry.invalidate_plugins_for_auth() | |||
214 |
|
230 | |||
215 | def get_all_settings(self, cache=False, from_request=True): |
|
231 | def get_all_settings(self, cache=False, from_request=True): | |
216 | from rhodecode.authentication.base import get_authn_registry |
|
|||
217 |
|
||||
218 | # defines if we use GLOBAL, or PER_REPO |
|
232 | # defines if we use GLOBAL, or PER_REPO | |
219 | repo = self._get_repo(self.repo) if self.repo else None |
|
233 | repo = self._get_repo(self.repo) if self.repo else None | |
220 | key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app" |
|
|||
221 |
|
234 | |||
222 | # initially try the requests context, this is the fastest |
|
235 | # initially try the requests context, this is the fastest | |
223 | # we only fetch global config |
|
236 | # we only fetch global config | |
@@ -229,8 +242,7 b' class SettingsModel(BaseModel):' | |||||
229 | if rc_config: |
|
242 | if rc_config: | |
230 | return rc_config |
|
243 | return rc_config | |
231 |
|
244 | |||
232 | region = rc_cache.get_or_create_region('sql_cache_short') |
|
245 | region, cache_key = self.get_cache_region() | |
233 | invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE |
|
|||
234 |
|
246 | |||
235 | @region.conditional_cache_on_arguments(condition=cache) |
|
247 | @region.conditional_cache_on_arguments(condition=cache) | |
236 | def _get_all_settings(name, key): |
|
248 | def _get_all_settings(name, key): | |
@@ -239,31 +251,17 b' class SettingsModel(BaseModel):' | |||||
239 | raise Exception('Could not get application settings !') |
|
251 | raise Exception('Could not get application settings !') | |
240 |
|
252 | |||
241 | settings = { |
|
253 | settings = { | |
242 |
'rhodecode_' + res |
|
254 | 'rhodecode_' + res.app_settings_name: res.app_settings_value | |
243 |
for res |
|
255 | for res in q | |
244 | } |
|
256 | } | |
245 | return settings |
|
257 | return settings | |
246 |
|
258 | |||
247 | inv_context_manager = rc_cache.InvalidationContext( |
|
259 | statsd = StatsdClient.statsd | |
248 | uid='cache_settings', invalidation_namespace=invalidation_namespace) |
|
260 | with statsd.timer('rhodecode_settings_timing.histogram', auto_send=True) as tmr: | |
249 | with inv_context_manager as invalidation_context: |
|
261 | result = _get_all_settings('rhodecode_settings', cache_key) | |
250 | # check for stored invalidation signal, and maybe purge the cache |
|
|||
251 | # before computing it again |
|
|||
252 | if invalidation_context.should_invalidate(): |
|
|||
253 | # NOTE:(marcink) we flush the whole sql_cache_short region, because it |
|
|||
254 | # reads different settings etc. It's little too much but those caches |
|
|||
255 | # are anyway very short lived and it's a safest way. |
|
|||
256 | region = rc_cache.get_or_create_region('sql_cache_short') |
|
|||
257 | region.invalidate() |
|
|||
258 | registry = get_current_registry() |
|
|||
259 | if registry: |
|
|||
260 | authn_registry = get_authn_registry(registry) |
|
|||
261 | if authn_registry: |
|
|||
262 | authn_registry.invalidate_plugins_for_auth() |
|
|||
263 |
|
262 | |||
264 | result = _get_all_settings('rhodecode_settings', key) |
|
263 | compute_time = tmr.ms / 1000. | |
265 |
|
|
264 | log.debug('Fetching app settings for key: %s took: %.4fs', cache_key, compute_time) | |
266 | inv_context_manager.compute_time) |
|
|||
267 |
|
265 | |||
268 | return result |
|
266 | return result | |
269 |
|
267 |
General Comments 0
You need to be logged in to leave comments.
Login now