cache-fix-8
All checks were successful
Deploy on push / deploy (push) Successful in 47s

This commit is contained in:
Untone 2024-05-30 20:26:53 +03:00
parent 2e2dc80718
commit afef19fae3

View File

@ -64,7 +64,7 @@ async def get_cached_author(author_id: int, get_with_stat):
if isinstance(cached_result, str): if isinstance(cached_result, str):
return json.loads(cached_result) return json.loads(cached_result)
elif get_with_stat: elif get_with_stat:
async with local_session() as session: with local_session() as session:
author_query = select(Author).filter(Author.id == author_id) author_query = select(Author).filter(Author.id == author_id)
[author] = get_with_stat(session.execute(author_query)) [author] = get_with_stat(session.execute(author_query))
if author: if author:
@ -98,7 +98,7 @@ async def get_cached_topic_authors(topic_id: int, topic_authors_query):
if isinstance(cached, str): if isinstance(cached, str):
authors_ids = json.loads(cached) authors_ids = json.loads(cached)
else: else:
async with local_session() as session: with local_session() as session:
authors_ids = [aid for (aid,) in session.execute(topic_authors_query)] authors_ids = [aid for (aid,) in session.execute(topic_authors_query)]
await redis.execute("SET", rkey, json.dumps(authors_ids)) await redis.execute("SET", rkey, json.dumps(authors_ids))
authors = await get_cached_authors_by_ids(authors_ids) authors = await get_cached_authors_by_ids(authors_ids)