From f88d96cb9272966e88a94a5d34e12cc9619c1679 Mon Sep 17 00:00:00 2001 From: hhyo Date: Sat, 31 Oct 2020 15:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=85=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E7=BC=93=E5=AD=98=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/config.py | 71 ++++++++++++----------------------- common/templates/config.html | 10 ++--- sql/templates/binlog2sql.html | 2 +- 3 files changed, 29 insertions(+), 54 deletions(-) diff --git a/common/config.py b/common/config.py index 029df256c5..de4865563a 100644 --- a/common/config.py +++ b/common/config.py @@ -8,7 +8,6 @@ from common.utils.permission import superuser_required from sql.models import Config from django.db import transaction -from django.core.cache import cache logger = logging.getLogger('default') @@ -19,37 +18,20 @@ def __init__(self): self.get_all_config() def get_all_config(self): - # 优先获取缓存数据 try: - sys_config = cache.get('sys_config') - except Exception as m: - sys_config = None - logger.error(f"读取缓存失败:{m}{traceback.format_exc()}") - - # 缓存获取失败从数据库获取并且尝试更新缓存 - if sys_config: + # 获取系统配置信息 + all_config = Config.objects.all().values('item', 'value') + sys_config = {} + for items in all_config: + if items['value'] in ('true', 'True'): + items['value'] = True + elif items['value'] in ('false', 'False'): + items['value'] = False + sys_config[items['item']] = items['value'] self.sys_config = sys_config - else: - try: - # 获取系统配置信息 - all_config = Config.objects.all().values('item', 'value') - sys_config = {} - for items in all_config: - if items['value'] in ('true', 'True'): - items['value'] = True - elif items['value'] in ('false', 'False'): - items['value'] = False - sys_config[items['item']] = items['value'] - self.sys_config = sys_config - except Exception as m: - logger.error(f"获取系统配置信息失败:{m}{traceback.format_exc()}") - self.sys_config = {} - else: - try: - # 更新缓存 - cache.set('sys_config', self.sys_config, timeout=None) - except Exception as m: - logger.error(f"更新缓存失败:{m}{traceback.format_exc()}") + except Exception as m: + logger.error(f"获取系统配置信息失败:{m}{traceback.format_exc()}") + self.sys_config = {} def get(self, key, default_value=None): value = self.sys_config.get(key, default_value) @@ -60,27 +42,21 @@ def get(self, key, default_value=None): def set(self, key, value): if value is True: - value = 'true' + db_value = 'true' elif value is False: - value = 'false' - config_item, created = Config.objects.get_or_create(item=key) - config_item.value = value - config_item.save() - # 删除并更新缓存 - try: - cache.delete('sys_config') - except Exception as m: - logger.error(f"删除缓存失败:{m}{traceback.format_exc()}") - finally: - self.get_all_config() + db_value = 'false' + else: + db_value = value + obj, created = Config.objects.update_or_create(item=key, defaults={"value": db_value}) + if created: + self.sys_config.update({key: value}) def replace(self, configs): result = {'status': 0, 'msg': 'ok', 'data': []} - # 清空并替换 try: - self.purge() with transaction.atomic(): + self.purge() Config.objects.bulk_create( [Config(item=items['key'].strip(), value=str(items['value']).strip()) for items in json.loads(configs)]) @@ -95,12 +71,11 @@ def replace(self, configs): def purge(self): """清除所有配置, 供测试以及replace方法使用""" try: - self.sys_config = {} - cache.delete('sys_config') + with transaction.atomic(): + Config.objects.all().delete() + self.sys_config = {} except Exception as m: logger.error(f"删除缓存失败:{m}{traceback.format_exc()}") - with transaction.atomic(): - Config.objects.all().delete() # 修改系统配置 diff --git a/common/templates/config.html b/common/templates/config.html index 7e29a16acf..daced0cb65 100755 --- a/common/templates/config.html +++ b/common/templates/config.html @@ -714,7 +714,7 @@

其他配置

-
当前审批流程:当前审批流程:当前审批流程:当前审批流程:对象过滤:
前端展示数量由解析范围参数控制,如果勾选了保存到文件,则会异步获取完整的SQL文件, 保存到项目downloads目录,起始时间过滤存在性能问题,建议使用position进行过滤, - 在开启邮件通知后,执行结束会通知给操作人 + 在开启消息通知后,执行结束会发送通知给操作人