Add cache to Translation.get_language
review1005002
This commit is contained in:
+10
-1
@@ -204,26 +204,35 @@ class Lang(ModelSQL, ModelView):
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
pool = Pool()
|
||||
Translation = pool.get('ir.translation')
|
||||
# Clear cache
|
||||
cls._lang_cache.clear()
|
||||
return super(Lang, cls).create(vlist)
|
||||
languages = super(Lang, cls).create(vlist)
|
||||
Translation._get_language_cache.clear()
|
||||
return languages
|
||||
|
||||
@classmethod
|
||||
def write(cls, langs, vals):
|
||||
pool = Pool()
|
||||
Translation = pool.get('ir.translation')
|
||||
# Clear cache
|
||||
cls._lang_cache.clear()
|
||||
super(Lang, cls).write(langs, vals)
|
||||
Translation._get_language_cache.clear()
|
||||
|
||||
@classmethod
|
||||
def delete(cls, langs):
|
||||
pool = Pool()
|
||||
Config = pool.get('ir.configuration')
|
||||
Translation = pool.get('ir.translation')
|
||||
for lang in langs:
|
||||
if lang.code == Config.get_language():
|
||||
cls.raise_user_error('delete_default')
|
||||
# Clear cache
|
||||
cls._lang_cache.clear()
|
||||
super(Lang, cls).delete(langs)
|
||||
Translation._get_language_cache.clear()
|
||||
|
||||
@staticmethod
|
||||
def _group(lang, s, monetary=None):
|
||||
|
||||
@@ -71,6 +71,7 @@ class Translation(ModelSQL, ModelView):
|
||||
searcher='search_model')
|
||||
_translation_cache = Cache('ir.translation', size_limit=10240,
|
||||
context=False)
|
||||
_get_language_cache = Cache('ir.translation')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
@@ -153,11 +154,15 @@ class Translation(ModelSQL, ModelView):
|
||||
|
||||
@classmethod
|
||||
def get_language(cls):
|
||||
result = cls._get_language_cache.get(None)
|
||||
if result is not None:
|
||||
return result
|
||||
pool = Pool()
|
||||
Lang = pool.get('ir.lang')
|
||||
langs = Lang.search([])
|
||||
res = [(lang.code, lang.name) for lang in langs]
|
||||
return res
|
||||
result = [(lang.code, lang.name) for lang in langs]
|
||||
cls._get_language_cache.set(None, result)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_src_md5(cls, src):
|
||||
|
||||
Reference in New Issue
Block a user