Fix an AttributeError on cache invalidation
This commit is contained in:
1 parent
bf377b260f
commit
b6229163bf
1 file changed
+12
-7
+12
-7
@@ -10,6 +10,14 @@ if TYPE_CHECKING:
|
|||||||
from twitch import Twitch
|
from twitch import Twitch
|
||||||
|
|
||||||
|
|
||||||
|
def _invalidate_cache(instance, *attrnames):
|
||||||
|
for name in attrnames:
|
||||||
|
try:
|
||||||
|
delattr(instance, name)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, data: JsonType):
|
def __init__(self, data: JsonType):
|
||||||
self.id: int = int(data["id"])
|
self.id: int = int(data["id"])
|
||||||
@@ -72,7 +80,7 @@ class BaseDrop:
|
|||||||
return self.claim_id is not None
|
return self.claim_id is not None
|
||||||
|
|
||||||
def _on_claim(self) -> None:
|
def _on_claim(self) -> None:
|
||||||
del self.preconditions
|
_invalidate_cache(self, "preconditions")
|
||||||
|
|
||||||
def update_claim(self, claim_id: str):
|
def update_claim(self, claim_id: str):
|
||||||
self.claim_id = claim_id
|
self.claim_id = claim_id
|
||||||
@@ -147,8 +155,7 @@ class TimedDrop(BaseDrop):
|
|||||||
return self.current_minutes / self.required_minutes
|
return self.current_minutes / self.required_minutes
|
||||||
|
|
||||||
def _on_minutes_changed(self) -> None:
|
def _on_minutes_changed(self) -> None:
|
||||||
del self.progress
|
_invalidate_cache(self, "progress", "remaining_minutes")
|
||||||
del self.remaining_minutes
|
|
||||||
self.campaign._on_minutes_changed()
|
self.campaign._on_minutes_changed()
|
||||||
|
|
||||||
async def claim(self) -> bool:
|
async def claim(self) -> bool:
|
||||||
@@ -222,11 +229,9 @@ class DropsCampaign:
|
|||||||
return sum(d.progress for d in self.timed_drops.values()) / self.total_drops
|
return sum(d.progress for d in self.timed_drops.values()) / self.total_drops
|
||||||
|
|
||||||
def _on_claim(self) -> None:
|
def _on_claim(self) -> None:
|
||||||
del self.claimed_drops
|
_invalidate_cache(self, "claimed_drops", "remaining_drops")
|
||||||
del self.remaining_drops
|
|
||||||
for drop in self.timed_drops.values():
|
for drop in self.timed_drops.values():
|
||||||
drop._on_claim()
|
drop._on_claim()
|
||||||
|
|
||||||
def _on_minutes_changed(self) -> None:
|
def _on_minutes_changed(self) -> None:
|
||||||
del self.progress
|
_invalidate_cache(self, "progress", "remaining_minutes")
|
||||||
del self.remaining_minutes
|
|
||||||
Reference in new issue
Block a user