From d096cd29a5dd0656936d501b5bf43b59d5583c62 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Sun, 20 Nov 2022 13:59:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20material=20cache=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/game/cache.py | 5 ++--- core/game/services.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/game/cache.py b/core/game/cache.py index a03ed56b..24123966 100644 --- a/core/game/cache.py +++ b/core/game/cache.py @@ -11,12 +11,11 @@ class GameCache: async def get_url_list(self, character_name: str): qname = f"{self.qname}:{character_name}" - return [str(str_data, encoding="utf-8") for str_data in await self.client.lrange(qname, 0, -1)] + return [str(str_data, encoding="utf-8") for str_data in await self.client.lrange(qname, 0, -1)][::-1] async def set_url_list(self, character_name: str, str_list: List[str]): qname = f"{self.qname}:{character_name}" await self.client.ltrim(qname, 1, 0) await self.client.lpush(qname, *str_list) await self.client.expire(qname, self.ttl) - count = await self.client.llen(qname) - return count + return await self.client.llen(qname) diff --git a/core/game/services.py b/core/game/services.py index 916aeac9..281a64d2 100644 --- a/core/game/services.py +++ b/core/game/services.py @@ -12,8 +12,11 @@ class GameStrategyService: self._collections = [839176, 839179, 839181, 1180811] else: self._collections = collections + self._special_posts = {"达达利亚": "21272578"} async def _get_strategy_from_hyperion(self, collection_id: int, character_name: str) -> int: + if character_name in self._special_posts: + return self._special_posts[character_name] post_id: int = -1 post_full_in_collection = await self._hyperion.get_post_full_in_collection(collection_id) for post_data in post_full_in_collection["posts"]: @@ -32,7 +35,7 @@ class GameStrategyService: async def get_strategy(self, character_name: str) -> str: cache = await self._cache.get_url_list(character_name) if len(cache) >= 1: - return cache[-1] + return cache[0] for collection_id in self._collections: post_id = await self._get_strategy_from_hyperion(collection_id, character_name) @@ -74,18 +77,18 @@ class GameMaterialService: async def get_material(self, character_name: str) -> str: cache = await self._cache.get_url_list(character_name) if len(cache) >= 1: - return cache[-1] - - for collection_id in self._collections: - post_id = await self._get_material_from_hyperion(collection_id, character_name) - if post_id != -1: - break + image_url_list = cache else: - return "" + for collection_id in self._collections: + post_id = await self._get_material_from_hyperion(collection_id, character_name) + if post_id != -1: + break + else: + return "" - artwork_info = await self._hyperion.get_post_info(2, post_id) - await self._cache.set_url_list(character_name, artwork_info.image_urls) - image_url_list = artwork_info.image_urls + artwork_info = await self._hyperion.get_post_info(2, post_id) + image_url_list = artwork_info.image_urls + await self._cache.set_url_list(character_name, image_url_list) if len(image_url_list) == 0: return "" elif len(image_url_list) == 1: