Skip to content

Commit e34d385

Browse files
fix: Refresh cache on PATCH request (#5497)
1 parent b78d0ac commit e34d385

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

app/api/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.api.schema.settings import SettingSchemaAdmin, SettingSchemaNonAdmin, SettingSchemaPublic
88
from app.models import db
99
from app.models.setting import Setting
10+
from app.settings import refresh_settings
1011

1112

1213
class Environment:
@@ -43,3 +44,7 @@ def before_get(self, args, kwargs):
4344
schema = SettingSchemaAdmin
4445
data_layer = {'session': db.session,
4546
'model': Setting}
47+
48+
def after_patch(self, result):
49+
# Update settings cache after PATCH
50+
refresh_settings()

app/settings/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from app.models.setting import Setting, Environment
77

88

9-
def get_settings():
9+
def get_settings(from_db=False):
1010
"""
1111
Use this to get latest system settings
1212
"""
13-
if 'custom_settings' in current_app.config:
13+
if not from_db and 'custom_settings' in current_app.config:
1414
return current_app.config['custom_settings']
1515
s = Setting.query.order_by(desc(Setting.id)).first()
1616
if s is None:
@@ -22,6 +22,11 @@ def get_settings():
2222
return current_app.config['custom_settings']
2323

2424

25+
def refresh_settings():
26+
# Force fetch settings from DB, thus refreshing it
27+
get_settings(from_db=True)
28+
29+
2530
def get_setts():
2631
return Setting.query.order_by(desc(Setting.id)).first()
2732

0 commit comments

Comments
 (0)