imports sort
Some checks failed
Deploy on push / deploy (push) Failing after 9s

This commit is contained in:
2024-08-09 09:37:06 +03:00
parent d0c1f33227
commit 208de158bc
18 changed files with 64 additions and 35 deletions

12
cache/cache.py vendored
View File

@@ -63,17 +63,17 @@ async def update_follower_stat(follower_id, entity_type, count):
# Get author from cache
async def get_cached_author(author_id: int):
async def get_cached_author(author_id: int, get_with_stat):
author_key = f"author:id:{author_id}"
result = await redis.execute("get", author_key)
if result:
return json.loads(result)
# Load from database if not found in cache
with local_session() as session:
author = session.execute(select(Author).where(Author.id == author_id)).scalar_one_or_none()
if author:
await cache_author(author.dict())
return author.dict()
q = select(Author).where(Author.id == author_id)
author = get_with_stat(q)
if author:
await cache_author(author.dict())
return author.dict()
return None

View File

@@ -1,5 +1,6 @@
import asyncio
from cache.cache import get_cached_author, cache_author, get_cached_topic, cache_topic
from cache.cache import cache_author, cache_topic, get_cached_author, get_cached_topic
from utils.logger import root_logger as logger

3
cache/triggers.py vendored
View File

@@ -1,9 +1,10 @@
from sqlalchemy import event
from cache.revalidator import revalidation_manager
from orm.author import Author, AuthorFollower
from orm.reaction import Reaction
from orm.shout import Shout, ShoutAuthor, ShoutReactionsFollower
from orm.topic import Topic, TopicFollower
from cache.revalidator import revalidation_manager
from utils.logger import root_logger as logger