##// 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 from collections import namedtuple
23 from collections import namedtuple
24 from functools import wraps
24 from functools import wraps
25
25
26 from rhodecode.lib import caches
26 from rhodecode.lib.caching_query import FromCache
27 from rhodecode.lib.caching_query import FromCache
27 from rhodecode.lib.utils2 import (
28 from rhodecode.lib.utils2 import (
28 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
29 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
@@ -201,14 +202,8 b' class SettingsModel(BaseModel):'
201 return res
202 return res
202
203
203 def get_all_settings(self, cache=False):
204 def get_all_settings(self, cache=False):
205 def _compute():
204 q = self._get_settings_query()
206 q = self._get_settings_query()
205 if cache:
206 repo = self._get_repo(self.repo) if self.repo else None
207 cache_key = (
208 "get_repo_{}_settings".format(repo.repo_id)
209 if repo else "get_hg_settings")
210 q = q.options(FromCache("sql_cache_short", cache_key))
211
212 if not q:
207 if not q:
213 raise Exception('Could not get application settings !')
208 raise Exception('Could not get application settings !')
214
209
@@ -218,6 +213,20 b' class SettingsModel(BaseModel):'
218 }
213 }
219 return settings
214 return settings
220
215
216 if cache:
217 repo = self._get_repo(self.repo) if self.repo else None
218 namespace = 'rhodecode_settings'
219 cache_manager = caches.get_cache_manager(
220 'sql_cache_short', namespace)
221 _cache_key = (
222 "get_repo_{}_settings".format(repo.repo_id)
223 if repo else "get_app_settings")
224
225 return cache_manager.get(_cache_key, createfunc=_compute)
226
227 else:
228 return _compute()
229
221 def get_auth_settings(self):
230 def get_auth_settings(self):
222 q = self._get_settings_query()
231 q = self._get_settings_query()
223 q = q.filter(
232 q = q.filter(
General Comments 0
You need to be logged in to leave comments. Login now