Skip to content

Commit

Permalink
fix: Fix caching mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Mar 3, 2024
1 parent 100f3fa commit 38dc2f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 4 additions & 7 deletions src/hoyo/enka_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ async def __aenter__(self) -> "EnkaAPI":
return self

def _update_cache_with_live_data(self, cache: EnkaCache, live_data: "ShowcaseResponse") -> None:
live_chara_data = {"live": True, "lang": self._lang.value}

if cache.genshin is None:
cache.genshin = pickle.dumps(live_data)
cache.extras.update(
{
str(char.id): {"live": True, "lang": self._lang.value}
for char in live_data.characters
}
)
cache.extras.update({str(char.id): live_chara_data for char in live_data.characters})
return

cache_data: ShowcaseResponse = pickle.loads(cache.genshin)

live_character_ids: list[int] = []
for character in live_data.characters:
live_character_ids.append(character.id)
cache.extras[str(character.id)].update({"live": True, "lang": self._lang.value})
cache.extras.get(str(character.id), {}).update(live_chara_data)

cache_characters_not_in_live: list["Character"] = []

Expand Down
11 changes: 4 additions & 7 deletions src/hoyo/mihomo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@ def __init__(self, language: "discord.Locale") -> None:
def _update_cache_with_live_data(
self, cache: EnkaCache, live_data: "StarrailInfoParsed"
) -> None:
live_chara_data = {"live": True, "lang": self.lang.value}

if cache.hsr is None:
cache.hsr = pickle.dumps(live_data)
cache.extras.update(
{
str(char.id): {"live": True, "lang": self.lang.value}
for char in live_data.characters
}
)
cache.extras.update({str(char.id): live_chara_data for char in live_data.characters})
return

cache_data: StarrailInfoParsed = pickle.loads(cache.hsr)

live_character_ids: list[str] = []
for character in live_data.characters:
live_character_ids.append(character.id)
cache.extras.get(str(character.id), {}).update({"live": True, "lang": self.lang.value})
cache.extras.get(character.id, {}).update(live_chara_data)

cache_characters_not_in_live: list["Character"] = []

Expand Down

0 comments on commit 38dc2f8

Please sign in to comment.