Skip to content

Commit 1bc0406

Browse files
committed
🔧 embedez: avoid recreating sessions
1 parent c607a1a commit 1bc0406

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/websites.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
__all__ = ('WebsiteLink', 'websites')
1313

14+
15+
session = aiohttp.ClientSession()
16+
1417
def call_if_valid(func: Callable) -> Callable:
1518
"""
1619
A static method decorator that ensures the wrapped function is executed only if
@@ -327,12 +330,11 @@ async def get_fixed_url(self) -> tuple[Optional[str], Optional[str]]:
327330
subdomain = self.route_fix_subdomain() + subdomain
328331
prepared_url = self.get_patched_url(self.match['domain'], subdomain, self.route_fix_post_path_segments())
329332
try:
330-
async with aiohttp.ClientSession() as session:
331-
async with session.get("https://embedez.com/api/v1/providers/combined", params={'q': prepared_url}, timeout=aiohttp.ClientTimeout(total=30)) as response:
332-
if response.status != 200:
333-
return None, None
334-
search_hash = (await response.json())['data']['key']
335-
return f"https://embedez.com/embed/{search_hash}", self.fixer_name
333+
async with session.get("https://embedez.com/api/v1/providers/combined", params={'q': prepared_url}, timeout=aiohttp.ClientTimeout(total=30)) as response:
334+
if response.status != 200:
335+
return None, None
336+
search_hash = (await response.json())['data']['key']
337+
return f"https://embedez.com/embed/{search_hash}", self.fixer_name
336338
except asyncio.TimeoutError:
337339
return None, None
338340

0 commit comments

Comments
 (0)