This commit is contained in:
12
cache/cache.py
vendored
12
cache/cache.py
vendored
@@ -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
|
||||
|
||||
|
||||
|
3
cache/revalidator.py
vendored
3
cache/revalidator.py
vendored
@@ -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
3
cache/triggers.py
vendored
@@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user