From 2c6e385b326dfa3ffae74f2db56acc7a35336fb2 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sat, 4 Dec 2021 16:21:01 +0100 Subject: [PATCH] Defer get_spade_url for some nice startup speedup --- channel.py | 8 +++++--- twitch.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/channel.py b/channel.py index 540861e..a026849 100644 --- a/channel.py +++ b/channel.py @@ -62,20 +62,20 @@ class Channel: self.id: int = 0 # temp, to be filled by get_stream self.name: str = channel_name self.url: str = f"{BASE_URL}/{channel_name}" - self._spade_url: str = await self.get_spade_url() + self._spade_url: Optional[str] = None self.stream: Optional[Stream] = None self._pending_stream_up: Optional[asyncio.Task[Any]] = None await self.get_stream() @classmethod - async def from_directory(cls, twitch: Twitch, data: Dict[str, Any]): + def from_directory(cls, twitch: Twitch, data: Dict[str, Any]): self = super().__new__(cls) self._twitch = twitch channel = data["broadcaster"] self.id = channel["id"] self.name = channel["displayName"] self.url = f"{BASE_URL}/{self.name}" - self._spade_url = await self.get_spade_url() + self._spade_url = None self.stream = Stream.from_directory(self, data) self._pending_stream_up = None return self @@ -187,6 +187,8 @@ class Channel: """ if not self.online: return + if self._spade_url is None: + self._spade_url = await self.get_spade_url() logger.debug(f"Sending minute-watched to {self.name}") async with self._twitch._session.post( self._spade_url, data=self._encode_payload() diff --git a/twitch.py b/twitch.py index 754f361..eeb2d17 100644 --- a/twitch.py +++ b/twitch.py @@ -384,7 +384,7 @@ class Twitch: }) ) live_streams[game] = [ - await Channel.from_directory(self, stream_channel_data["node"]) + Channel.from_directory(self, stream_channel_data["node"]) for stream_channel_data in response["data"]["game"]["streams"]["edges"] ] return live_streams