feat: 通过接口重新加载config

This commit is contained in:
caoqianming 2023-07-10 15:12:45 +08:00
parent d2afb309b5
commit a8576212a1
2 changed files with 6 additions and 3 deletions

View File

@ -742,7 +742,10 @@ class SysConfigView(MyLoggingMixin, APIView):
获取config json
"""
return Response(get_sysconfig())
reload = False
if request.query_params.get('reload', None):
reload = True
return Response(get_sysconfig(reload=reload))
@swagger_auto_schema(request_body=Serializer)
def put(self, request, format=None):

View File

@ -25,7 +25,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SYS_JSON_PATH = os.path.join(BASE_DIR, 'server/conf.json')
def get_sysconfig(reload=False):
config = cache.get('system_config')
config = cache.get('system_config', None)
if config is None or reload:
# 读取配置文件
if not os.path.exists(SYS_JSON_PATH):
@ -54,7 +54,7 @@ def update_sysconfig(new_dict):
f.write(json.dumps(config, indent=4, ensure_ascii=False).encode('utf-8'))
cache.set('system_config', config)
# 重启时需要reload
# 重启时需要reload 不能这样操作, 会使缓存有问题,我也不知道为什么
# get_sysconfig(reload=True)
# SECURITY WARNING: keep the secret key used in production secret!