cache-reimplement-2
All checks were successful
Deploy on push / deploy (push) Successful in 1m4s

This commit is contained in:
2024-05-21 01:40:57 +03:00
parent 3742528e3a
commit 4c1fbf64a2
13 changed files with 292 additions and 326 deletions

View File

@@ -1,5 +1,4 @@
import asyncio
import json
from sqlalchemy import event, select
@@ -8,10 +7,8 @@ from orm.reaction import Reaction
from orm.shout import Shout, ShoutAuthor
from orm.topic import Topic, TopicFollower
from resolvers.stat import get_with_stat
from services.cache import cache_author, cache_follow_author_change, cache_follows
from services.encoders import CustomJSONEncoder
from services.cache import cache_author, cache_follows, cache_topic
from services.logger import root_logger as logger
from services.rediscache import redis
DEFAULT_FOLLOWS = {
"topics": [],
@@ -30,12 +27,7 @@ async def handle_author_follower_change(
[follower] = get_with_stat(follower_query)
if follower and author:
await cache_author(author.dict())
await cache_follows(
follower.dict(), "author", author.dict(), is_insert
) # cache_author(follower_dict) inside
await cache_follow_author_change(
follower.dict(), author.dict(), is_insert
) # cache_author(follower_dict) inside
await cache_follows(follower.id, "author", author.id, is_insert)
async def handle_topic_follower_change(
@@ -47,11 +39,9 @@ async def handle_topic_follower_change(
follower_query = select(Author).filter(Author.id == follower_id)
[follower] = get_with_stat(follower_query)
if follower and topic:
await cache_topic(topic.dict())
await cache_author(follower.dict())
await redis.execute(
"SET", f"topic:{topic.id}", json.dumps(topic.dict(), cls=CustomJSONEncoder)
)
await cache_follows(follower.dict(), "topic", topic.dict(), is_insert)
await cache_follows(follower.id, "topic", topic.id, is_insert)
# handle_author_follow and handle_topic_follow -> cache_author, cache_follows, cache_followers