cached-request-9
Some checks failed
deploy / deploy (push) Failing after 1m1s

This commit is contained in:
2023-12-19 20:19:16 +03:00
parent 2380e88168
commit 2253bcf956
6 changed files with 26 additions and 56 deletions

View File

@@ -29,15 +29,6 @@ def _request_endpoint(query_name, body) -> dict:
def get_all_authors():
global cached_authors, last_update_time
# Check if cached data is available and not expired
if cached_authors is not None and (datetime.now() - last_update_time) < update_interval:
print("[services.core] Returning cached authors data")
return cached_authors
authors_by_user = {}
authors_by_id = {}
query_name = "get_authors_all"
gql = {
@@ -45,18 +36,21 @@ def get_all_authors():
"variables": None,
}
# Make a request to load authors
authors = _request_endpoint(query_name, gql)
return _request_endpoint(query_name, gql)
for a in list(authors):
authors_by_user[a["user"]] = a
authors_by_id[a["id"]] = a
# Cache the authors data and update the last update time
cached_authors = authors_by_user, authors_by_id
last_update_time = datetime.now()
def get_author_by_user(user: str):
operation = "GetAuthorId"
query_name = "get_author_id"
gql = {
"query": f"query {operation}($user: String!) {{ {query_name}(user: $user){{ id }} }}",
"operationName": operation,
"variables": {"user": user},
}
return authors_by_user, authors_by_id
author = _request_endpoint(query_name, gql).popitem()
return author
def get_my_followed() -> List[ChatMember]:
@@ -67,6 +61,5 @@ def get_my_followed() -> List[ChatMember]:
"variables": None,
}
return _request_endpoint(query_name, gql).get(
"authors", []
) # Ensure you're returning the correct part of the response
result = _request_endpoint(query_name, gql)
return result.get("authors", [])