Skip to content

Commit

Permalink
fix: persist sideboards
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Apr 1, 2024
1 parent 3b547a7 commit 2a6ba66
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion twitch_hdt_ebs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import string
from collections import defaultdict
from typing import Any, Dict, List, Optional

import jwt
Expand Down Expand Up @@ -199,15 +200,24 @@ def cache_deck_data(self, data, version: int, config: dict) -> bool:

cards_list = []

for dbf_id, current, initial in deck_data.get("cards", []):
for dbf_id, _, initial in deck_data.get("cards", []):
for i in range(initial):
cards_list.append(dbf_id)

cards_list.sort()

sideboards = defaultdict(list)

for owner_dbf_id, dbf_id, _, initial in deck_data.get("sideboards", []):
for i in range(initial):
sideboards[owner_dbf_id].append(dbf_id)

sideboards = {o: sorted(c) for o, c in sideboards.items()}

cache_key = f"twitch_hdt_live_id_{self.request.twitch_user_id}"
caches["default"].set(cache_key, {
"deck": cards_list,
"sideboards": sideboards,
"hero": deck_data.get("hero"),
"format": deck_data.get("format"),
"rank": data.get("rank"),
Expand Down

0 comments on commit 2a6ba66

Please sign in to comment.