From 6689b28a70cebb31c523d6e19ceaaa259d7b4f1d Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sat, 22 Jan 2022 22:57:26 +0100 Subject: [PATCH] Speed up get_drop --- twitch.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/twitch.py b/twitch.py index c874bb7..0914184 100644 --- a/twitch.py +++ b/twitch.py @@ -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: