##// END OF EJS Templates
settings: use cache on whole result not just the query since it's the computation...
marcink -
r259:f75d6c26 default
parent child Browse files
Show More
@@ -23,6 +23,7 b' import logging'
23 23 from collections import namedtuple
24 24 from functools import wraps
25 25
26 from rhodecode.lib import caches
26 27 from rhodecode.lib.caching_query import FromCache
27 28 from rhodecode.lib.utils2 import (
28 29 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
@@ -201,22 +202,30 b' class SettingsModel(BaseModel):'
201 202 return res
202 203
203 204 def get_all_settings(self, cache=False):
204 q = self._get_settings_query()
205 def _compute():
206 q = self._get_settings_query()
207 if not q:
208 raise Exception('Could not get application settings !')
209
210 settings = {
211 'rhodecode_' + result.app_settings_name: result.app_settings_value
212 for result in q
213 }
214 return settings
215
205 216 if cache:
206 217 repo = self._get_repo(self.repo) if self.repo else None
207 cache_key = (
218 namespace = 'rhodecode_settings'
219 cache_manager = caches.get_cache_manager(
220 'sql_cache_short', namespace)
221 _cache_key = (
208 222 "get_repo_{}_settings".format(repo.repo_id)
209 if repo else "get_hg_settings")
210 q = q.options(FromCache("sql_cache_short", cache_key))
223 if repo else "get_app_settings")
211 224
212 if not q:
213 raise Exception('Could not get application settings !')
225 return cache_manager.get(_cache_key, createfunc=_compute)
214 226
215 settings = {
216 'rhodecode_' + result.app_settings_name: result.app_settings_value
217 for result in q
218 }
219 return settings
227 else:
228 return _compute()
220 229
221 230 def get_auth_settings(self):
222 231 q = self._get_settings_query()
General Comments 0
You need to be logged in to leave comments. Login now