From 90c01d8326c3c4a7952de694def6ed1c15aa13cc Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 18 十二月 2023 18:34:32 +0800 Subject: [PATCH] 输出接口优化 --- third_data/kpl_data_manager.py | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/third_data/kpl_data_manager.py b/third_data/kpl_data_manager.py index 1d5e713..e4fec08 100644 --- a/third_data/kpl_data_manager.py +++ b/third_data/kpl_data_manager.py @@ -49,6 +49,7 @@ __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() __current_code_reason_dict = {} __current_reason_codes_dict = {} + __records_cache = {} @classmethod def __load_hist_and_blocks(cls, code): @@ -146,10 +147,20 @@ mysqldb = mysql_data.Mysqldb() return mysqldb.select_all(f"select * from kpl_limit_up_record where _day='{day}'") + @classmethod + def list_all_cache(cls, day): + if day in cls.__records_cache: + return cls.__records_cache[day] + fdata = cls.list_all(day) + if fdata: + cls.__records_cache[day] = fdata + return fdata + @staticmethod def list_by_code(code, day): mysqldb = mysql_data.Mysqldb() return mysqldb.select_all(f"select * from kpl_limit_up_record where _code='{code}' and _day='{day}'") + @staticmethod def list_by_block(block_name, day): @@ -224,6 +235,7 @@ class KPLDataManager: __latest_datas = {} kpl_data_update_info = {} + __file_content_cache = {} @classmethod def __save_in_file(cls, key, datas): @@ -257,6 +269,18 @@ return None @classmethod + def get_from_file_cache(cls, type, day): + key = f"{type}-{day}" + if key in cls.__file_content_cache: + return cls.__file_content_cache.get(key) + fdata = cls.get_from_file(type, day) + if fdata: + cls.__file_content_cache[key] = fdata + return fdata + + + + @classmethod # 鑾峰彇鏈�杩戝嚑澶╃殑鏁版嵁锛屾牴鎹棩鏈熷�掑簭杩斿洖 def get_latest_from_file(cls, type, count): files = os.listdir(constant.CACHE_PATH) -- Gitblit v1.8.0