Speed up get_drop

This commit is contained in:
DevilXD
2022-01-22 22:57:26 +01:00
parent a387482962
commit 6689b28a70

View File

@@ -772,6 +772,16 @@ class Twitch:
self.inventory[game].append(campaign)
def get_drop(self, drop_id: str) -> Optional[TimedDrop]:
"""
Returns a drop from the inventory, based on it's ID.
"""
# try it with the currently selected game first
if self.game is not None:
for campaign in self.inventory[self.game]:
drop = campaign.timed_drops.get(drop_id)
if drop is not None:
return drop
# fallback to checking all campaigns
for campaign in chain(*self.inventory.values()):
drop = campaign.timed_drops.get(drop_id)
if drop is not None: