You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The join_all variants and correspndence methods are now VERY slow. Some of this could probably be elevated by postponing the api-requests from the init of the classes, and building up from the get_json-function as async / await. Finally doing a asyncio.gather() on all the "fetch" methods on the postponed API-calls from the class inits.
asyncdefget_json(url: str, params: dict) ->Any:
"""Asynchronously fetch JSON data from the KLASS API. Args: url (str): The API URL. params (dict): Query parameters. Returns: Any: JSON response. """asyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(url, headers=config.HEADERS, params=params) asresponse:
response.raise_for_status()
returnawaitresponse.json()
The functions calling get_json, need to be async and await get_json and so on.
When you want to fire off multiple requests at once, you may want to do a .gather():
asyncdeffetch_all_variants(variants: list[KlassVariant]):
"""Fetch API data for multiple KlassVariant instances concurrently."""tasks= [variant.fetch() forvariantinvariants]
awaitasyncio.gather(*tasks)
The text was updated successfully, but these errors were encountered:
Description
The join_all variants and correspndence methods are now VERY slow. Some of this could probably be elevated by postponing the api-requests from the init of the classes, and building up from the get_json-function as async / await. Finally doing a asyncio.gather() on all the "fetch" methods on the postponed API-calls from the class inits.
The functions calling get_json, need to be async and await get_json and so on.
When you want to fire off multiple requests at once, you may want to do a .gather():
The text was updated successfully, but these errors were encountered: