Speed up get_drop
This commit is contained in:
1 parent
a387482962
commit
6689b28a70
1 file changed
+10
@@ -772,6 +772,16 @@ class Twitch:
|
|||||||
self.inventory[game].append(campaign)
|
self.inventory[game].append(campaign)
|
||||||
|
|
||||||
def get_drop(self, drop_id: str) -> Optional[TimedDrop]:
|
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()):
|
for campaign in chain(*self.inventory.values()):
|
||||||
drop = campaign.timed_drops.get(drop_id)
|
drop = campaign.timed_drops.get(drop_id)
|
||||||
if drop is not None:
|
if drop is not None:
|
||||||
|
|||||||
Reference in new issue
Block a user