Show More
@@ -3144,6 +3144,7 class CacheKey(Base, BaseModel): | |||||
3144 | CACHE_TYPE_README = 'README' |
|
3144 | CACHE_TYPE_README = 'README' | |
3145 | # namespaces used to register process/thread aware caches |
|
3145 | # namespaces used to register process/thread aware caches | |
3146 | REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}' |
|
3146 | REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}' | |
|
3147 | SETTINGS_INVALIDATION_NAMESPACE = 'system_settings' | |||
3147 |
|
3148 | |||
3148 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
3149 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
3149 | cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None) |
|
3150 | cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None) |
@@ -21,7 +21,6 | |||||
21 | import os |
|
21 | import os | |
22 | import hashlib |
|
22 | import hashlib | |
23 | import logging |
|
23 | import logging | |
24 | import time |
|
|||
25 | from collections import namedtuple |
|
24 | from collections import namedtuple | |
26 | from functools import wraps |
|
25 | from functools import wraps | |
27 | import bleach |
|
26 | import bleach | |
@@ -32,7 +31,7 from rhodecode.lib.utils2 import ( | |||||
32 | from rhodecode.lib.vcs.backends import base |
|
31 | from rhodecode.lib.vcs.backends import base | |
33 | from rhodecode.model import BaseModel |
|
32 | from rhodecode.model import BaseModel | |
34 | from rhodecode.model.db import ( |
|
33 | from rhodecode.model.db import ( | |
35 | RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting) |
|
34 | RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting, CacheKey) | |
36 | from rhodecode.model.meta import Session |
|
35 | from rhodecode.model.meta import Session | |
37 |
|
36 | |||
38 |
|
37 | |||
@@ -207,14 +206,12 class SettingsModel(BaseModel): | |||||
207 | return res |
|
206 | return res | |
208 |
|
207 | |||
209 | def invalidate_settings_cache(self): |
|
208 | def invalidate_settings_cache(self): | |
210 | # NOTE:(marcink) we flush the whole sql_cache_short region, because it |
|
209 | invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE | |
211 | # reads different settings etc. It's little too much but those caches are |
|
210 | CacheKey.set_invalidate(invalidation_namespace) | |
212 | # anyway very short lived and it's a safest way. |
|
|||
213 | region = rc_cache.get_or_create_region('sql_cache_short') |
|
|||
214 | region.invalidate() |
|
|||
215 |
|
211 | |||
216 | def get_all_settings(self, cache=False): |
|
212 | def get_all_settings(self, cache=False): | |
217 | region = rc_cache.get_or_create_region('sql_cache_short') |
|
213 | region = rc_cache.get_or_create_region('sql_cache_short') | |
|
214 | invalidation_namespace = CacheKey.SETTINGS_INVALIDATION_NAMESPACE | |||
218 |
|
215 | |||
219 | @region.conditional_cache_on_arguments(condition=cache) |
|
216 | @region.conditional_cache_on_arguments(condition=cache) | |
220 | def _get_all_settings(name, key): |
|
217 | def _get_all_settings(name, key): | |
@@ -230,10 +227,23 class SettingsModel(BaseModel): | |||||
230 |
|
227 | |||
231 | repo = self._get_repo(self.repo) if self.repo else None |
|
228 | repo = self._get_repo(self.repo) if self.repo else None | |
232 | key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app" |
|
229 | key = "settings_repo.{}".format(repo.repo_id) if repo else "settings_app" | |
233 | start = time.time() |
|
230 | ||
|
231 | inv_context_manager = rc_cache.InvalidationContext( | |||
|
232 | uid='cache_settings', invalidation_namespace=invalidation_namespace) | |||
|
233 | with inv_context_manager as invalidation_context: | |||
|
234 | # check for stored invalidation signal, and maybe purge the cache | |||
|
235 | # before computing it again | |||
|
236 | if invalidation_context.should_invalidate(): | |||
|
237 | # NOTE:(marcink) we flush the whole sql_cache_short region, because it | |||
|
238 | # reads different settings etc. It's little too much but those caches | |||
|
239 | # are anyway very short lived and it's a safest way. | |||
|
240 | region = rc_cache.get_or_create_region('sql_cache_short') | |||
|
241 | region.invalidate() | |||
|
242 | ||||
234 | result = _get_all_settings('rhodecode_settings', key) |
|
243 | result = _get_all_settings('rhodecode_settings', key) | |
235 | total = time.time() - start |
|
244 | log.debug( | |
236 |
|
|
245 | 'Fetching app settings for key: %s took: %.3fs', key, | |
|
246 | inv_context_manager.compute_time) | |||
237 |
|
247 | |||
238 | return result |
|
248 | return result | |
239 |
|
249 |
General Comments 0
You need to be logged in to leave comments.
Login now