use-cached-following

This commit is contained in:
Untone 2024-03-12 15:28:20 +03:00
parent 26a527473f
commit d1a510b093

View File

@ -12,7 +12,7 @@ from orm.community import Community
from orm.reaction import Reaction
from orm.shout import Shout, ShoutReactionsFollower
from orm.topic import Topic, TopicFollower
from resolvers.stat import get_with_stat, author_follows_topics, author_follows_authors
from resolvers.stat import get_authors_with_stat_cached, author_follows_topics, author_follows_authors, get_with_stat
from services.auth import login_required
from services.db import local_session
from services.cache import (
@ -34,7 +34,7 @@ async def follow(_, info, what, slug):
user_id = info.context.get('user_id')
if not user_id:
return {"error": "unauthorized"}
[follower] = get_with_stat(select(Author).select_from(Author).filter(Author.user == user_id))
[follower] = get_authors_with_stat_cached(select(Author).select_from(Author).filter(Author.user == user_id))
if not follower:
return {"error": "cant find follower"}
@ -42,7 +42,7 @@ async def follow(_, info, what, slug):
error = author_follow(follower.id, slug)
if not error:
logger.debug(f'@{follower.slug} followed @{slug}')
[author] = get_with_stat(select(Author).select_from(Author).where(Author.slug == slug))
[author] = get_authors_with_stat_cached(select(Author).select_from(Author).where(Author.slug == slug))
if not author:
return {"error": "author is not found"}
follows = await update_follows_for_author(follower, 'author', author.dict(), True)
@ -80,7 +80,7 @@ async def unfollow(_, info, what, slug):
if not user_id:
return {"error": "unauthorized"}
follower_query = select(Author).filter(Author.user == user_id)
[follower] = get_with_stat(follower_query)
[follower] = get_authors_with_stat_cached(follower_query)
if not follower:
return {"error": "follower profile is not found"}
@ -88,7 +88,7 @@ async def unfollow(_, info, what, slug):
error = author_unfollow(follower.id, slug)
if not error:
logger.info(f'@{follower.slug} unfollowing @{slug}')
[author] = get_with_stat(select(Author).where(Author.slug == slug))
[author] = get_authors_with_stat_cached(select(Author).where(Author.slug == slug))
if not author:
return {"error": "cant find author"}
_followers = await update_followers_for_author(follower, author, False)