remove redundant stuff

This commit is contained in:
Fengqing Liu
2025-10-19 17:08:18 +11:00
parent e8144e9591
commit d466f46d6f
39 changed files with 372 additions and 573 deletions

View File

@@ -63,16 +63,12 @@ class GQLClient:
self._qgl_limiter = RateLimiter(capacity=5, window=1)
@overload
async def request(self, ops: GQLOperation) -> JsonType:
...
async def request(self, ops: GQLOperation) -> JsonType: ...
@overload
async def request(self, ops: list[GQLOperation]) -> list[JsonType]:
...
async def request(self, ops: list[GQLOperation]) -> list[JsonType]: ...
async def request(
self, ops: GQLOperation | list[GQLOperation]
) -> JsonType | list[JsonType]:
async def request(self, ops: GQLOperation | list[GQLOperation]) -> JsonType | list[JsonType]:
"""
Execute one or more GraphQL operations.
@@ -105,9 +101,7 @@ class GQLClient:
"POST",
"https://gql.twitch.tv/gql",
json=ops,
headers=auth_state.headers(
user_agent=self._client_type.USER_AGENT, gql=True
),
headers=auth_state.headers(user_agent=self._client_type.USER_AGENT, gql=True),
) as response:
response_json: JsonType | list[JsonType] = await response.json()
@@ -123,13 +117,9 @@ class GQLClient:
if "errors" in response_json:
for error_dict in response_json["errors"]:
if "message" in error_dict:
if (
single_retry
and error_dict["message"]
in (
"service error",
"PersistedQueryNotFound",
)
if single_retry and error_dict["message"] in (
"service error",
"PersistedQueryNotFound",
):
logger.error(
f"Retrying a {error_dict['message']} for "
@@ -160,9 +150,7 @@ class GQLClient:
raise GQLException(response_json["errors"])
# Other error handling
elif "error" in response_json:
raise GQLException(
f"{response_json['error']}: {response_json['message']}"
)
raise GQLException(f"{response_json['error']}: {response_json['message']}")
if force_retry:
break

View File

@@ -25,6 +25,7 @@ from src.utils import ExponentialBackoff
if TYPE_CHECKING:
from src.config import ClientInfo
from src.config.settings import Settings
from src.core.client import Twitch
from src.web.gui_manager import WebGUIManager
@@ -46,6 +47,7 @@ class HTTPClient:
self,
settings: Settings,
gui: WebGUIManager,
twitch: Twitch,
client_type: ClientInfo,
):
"""
@@ -56,12 +58,15 @@ class HTTPClient:
settings : Settings
Application settings for connection quality and proxy configuration
gui : WebGUIManager
GUI manager for user notifications and close detection
GUI manager for user notifications
twitch : Twitch
Twitch client for state checking
client_type : ClientInfo
Client type information (User-Agent, Client-ID, etc.)
"""
self.settings = settings
self.gui = gui
self._twitch = twitch
self._client_type = client_type
self._session: aiohttp.ClientSession | None = None
@@ -163,7 +168,9 @@ class HTTPClient:
backoff = ExponentialBackoff(maximum=3 * 60)
for delay in backoff:
if self.gui.close_requested:
from src.config import State
if self._twitch._state == State.EXIT:
raise ExitRequest()
elif (
invalidate_after is not None
@@ -174,9 +181,7 @@ class HTTPClient:
try:
response: aiohttp.ClientResponse | None = None
response = await self.gui.coro_unless_closed(
session.request(method, url, **kwargs)
)
response = await session.request(method, url, **kwargs)
assert response is not None
logger.debug(f"Response: {response.status}: {response}")
@@ -203,9 +208,8 @@ class HTTPClient:
if response is not None:
response.release()
# Wait for the backoff delay or until the GUI closes
with asyncio.suppress(asyncio.TimeoutError):
await asyncio.wait_for(self.gui.wait_until_closed(), timeout=delay)
# Wait for the backoff delay
await asyncio.sleep(delay)
async def close(self) -> None:
"""