From 74fdf9110271d4c7b82f86114579cd9239ec74d1 Mon Sep 17 00:00:00 2001 From: envolution Date: Tue, 19 Nov 2024 23:01:23 -0500 Subject: [PATCH] aa --- nvchecker_source/github-test.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nvchecker_source/github-test.py b/nvchecker_source/github-test.py index 88b3317..8b138f9 100644 --- a/nvchecker_source/github-test.py +++ b/nvchecker_source/github-test.py @@ -6,7 +6,7 @@ import asyncio import json # Added for JSON handling import structlog - +http_client = None from nvchecker.api import ( VersionResult, Entry, AsyncCache, KeyManager, HTTPError, session, RichResult, GetVersionError, @@ -21,6 +21,14 @@ GITHUB_GRAPHQL_URL = 'https://api.%s/graphql' async def get_version(name, conf, **kwargs): global RATE_LIMITED_ERROR, ALLOW_REQUEST + global http_client + + # Initialize the HTTP client if not already done + if http_client is None: + if asyncio.iscoroutine(session): + http_client = await session + http_client = session + if RATE_LIMITED_ERROR: raise RuntimeError('rate limited') @@ -115,7 +123,7 @@ async def get_latest_tag(key: Tuple[str, str, str, str]) -> RichResult: # Make GraphQL query query_vars = QUERY_GITHUB.replace("$owner", owner).replace("$name", reponame) - async with session.post( + async with http_client.post( GITHUB_GRAPHQL_URL % host, headers=headers, json={'query': query_vars} @@ -148,7 +156,7 @@ async def get_latest_release_with_prereleases(key: Tuple[str, str, str, str]) -> # Make GraphQL query query_vars = QUERY_GITHUB.replace("$owner", owner).replace("$name", reponame) - async with session.post( + async with http_client.post( GITHUB_GRAPHQL_URL % host, headers=headers, json={'query': query_vars} @@ -205,7 +213,7 @@ async def get_version_real( # Make GraphQL query query_vars = QUERY_GITHUB.replace("$owner", owner).replace("$name", reponame) - async with session.post( + async with http_client.post( GITHUB_GRAPHQL_URL % host, headers=headers, json={'query': query_vars}