mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Cache default currency (#5723)
- Prevents multiple (failing) database hits during server startup - Prevents multiple (failing) database hits during migration checks
This commit is contained in:
parent
8f75758c45
commit
7ff5654448
@ -3,6 +3,7 @@
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
|
||||
from moneyed import CURRENCIES
|
||||
|
||||
@ -14,8 +15,13 @@ def currency_code_default():
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
cached_value = cache.get('currency_code_default', '')
|
||||
|
||||
if cached_value:
|
||||
return cached_value
|
||||
|
||||
try:
|
||||
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY', create=True, cache=True)
|
||||
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY', backup_value='', create=True, cache=True)
|
||||
except Exception: # pragma: no cover
|
||||
# Database may not yet be ready, no need to throw an error here
|
||||
code = ''
|
||||
@ -23,6 +29,9 @@ def currency_code_default():
|
||||
if code not in CURRENCIES:
|
||||
code = 'USD' # pragma: no cover
|
||||
|
||||
# Cache the value for a short amount of time
|
||||
cache.set('currency_code_default', code, 30)
|
||||
|
||||
return code
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user