mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-22 15:37:21 +00:00
🐛 Fix material cache error
This commit is contained in:
parent
e83a9fd8cb
commit
d096cd29a5
@ -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)
|
||||
|
@ -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,8 +77,8 @@ 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]
|
||||
|
||||
image_url_list = cache
|
||||
else:
|
||||
for collection_id in self._collections:
|
||||
post_id = await self._get_material_from_hyperion(collection_id, character_name)
|
||||
if post_id != -1:
|
||||
@ -84,8 +87,8 @@ class GameMaterialService:
|
||||
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
|
||||
await self._cache.set_url_list(character_name, image_url_list)
|
||||
if len(image_url_list) == 0:
|
||||
return ""
|
||||
elif len(image_url_list) == 1:
|
||||
|
Loading…
Reference in New Issue
Block a user