From 1691f5c11c08c218162223492e6400a65085142a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E5=B9=BF?= Date: Thu, 22 Jun 2023 19:37:25 +0800 Subject: [PATCH] fix[trade]cache data should follow type --- src/plugins/jx3/price_goods/lib/GoodsBase.py | 2 +- src/plugins/jx3/price_goods/lib/GoodsInfoFullExt.py | 6 +++--- src/plugins/jx3/price_goods/lib/GoodsSerializer.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/jx3/price_goods/lib/GoodsBase.py b/src/plugins/jx3/price_goods/lib/GoodsBase.py index 38fcee9bb..5aee56d3c 100644 --- a/src/plugins/jx3/price_goods/lib/GoodsBase.py +++ b/src/plugins/jx3/price_goods/lib/GoodsBase.py @@ -54,7 +54,7 @@ def __repr__(self) -> str: @property def priority(self) -> int: v_bind = 1 if self.bind_type == GoodsBindType.BindOnPick else 0 - v_create_id = self.ui_id + v_create_id = self.ui_id or 0 return 1e8 * self.u_popularity - v_bind * 1e12 + v_create_id @property diff --git a/src/plugins/jx3/price_goods/lib/GoodsInfoFullExt.py b/src/plugins/jx3/price_goods/lib/GoodsInfoFullExt.py index 6d78b9647..87aa34fbf 100644 --- a/src/plugins/jx3/price_goods/lib/GoodsInfoFullExt.py +++ b/src/plugins/jx3/price_goods/lib/GoodsInfoFullExt.py @@ -4,12 +4,12 @@ def check_cache_integrity(current_cache: dict, new_data: dict): # 当前缓存没有缓存品数,应为其缓存 - cached_level = 'level' in current_cache + cached_level = not current_cache.get('level') is None should_update_cache = not cached_level if not should_update_cache: return current_cache['level'] = new_data.get('Level') - CACHE_Goods[current_cache['id']] = current_cache + CACHE_Goods[current_cache['id']] = dict2obj(GoodsInfo(), current_cache) flush_CACHE_Goods() @@ -22,7 +22,7 @@ async def from_id(id: str) -> GoodsInfoFull: if not cache_data is None: current_cache = cache_data.to_dict() check_cache_integrity(current_cache, data) - + x = copy.deepcopy(current_cache) x.update(data) data = x diff --git a/src/plugins/jx3/price_goods/lib/GoodsSerializer.py b/src/plugins/jx3/price_goods/lib/GoodsSerializer.py index 188f66074..2a0312744 100644 --- a/src/plugins/jx3/price_goods/lib/GoodsSerializer.py +++ b/src/plugins/jx3/price_goods/lib/GoodsSerializer.py @@ -28,6 +28,7 @@ def default(self, o) -> str: def flush_CACHE_Goods_Common(cache_file: str, target_dict: dict): - d = dict([key, target_dict[key].__dict__] for key in target_dict) + d = dict([key, target_dict[key].__dict__ if not type( + target_dict[key]) == dict else target_dict[key]] for key in target_dict) data = json.dumps(d, cls=GoodsSerializerEncoder) write(cache_file, data)