query_follows-fix
Some checks are pending
Deploy to core / deploy (push) Waiting to run

This commit is contained in:
Untone 2024-02-21 18:13:43 +03:00
parent 67fa44b062
commit ab31d0d296

View File

@ -89,46 +89,52 @@ async def unfollow(_, info, what, slug):
def query_follows(user_id: str): def query_follows(user_id: str):
topics = set()
authors = set()
# communities = []
with local_session() as session: with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first() author = session.query(Author).filter(Author.user == user_id).first()
if isinstance(author, Author): if isinstance(author, Author):
author_id = author.id author_id = author.id
aliased_author = aliased(Author) aliased_author = aliased(Author)
authors_query = ( authors_query = (
session.query(aliased_author, AuthorFollower) session.query(aliased_author)
.join(AuthorFollower, AuthorFollower.follower == author_id) .join(AuthorFollower, AuthorFollower.follower == author_id)
.filter(AuthorFollower.author == aliased_author.id) .filter(AuthorFollower.author == aliased_author.id)
# .options(load_only(aliased_author.id)) # TODO: Exclude unnecessary columns
.dicts()
.all()
) )
topics_query = ( topics_query = (
session.query(Topic, TopicFollower) session.query(Topic)
.join(TopicFollower, TopicFollower.follower == author_id) .join(TopicFollower, TopicFollower.follower == author_id)
.filter(TopicFollower.topic == Topic.id) .filter(TopicFollower.topic == Topic.id)
# .options(load_only(Topic.id)) # TODO: Exclude unnecessary columns
.dicts()
.all()
) )
# NOTE: this loads separated paginating query # Convert query results to lists of dictionaries
authors = set(authors_query)
topics = set(topics_query)
# shouts_query = ( # shouts_query = (
# session.query(Shout, ShoutReactionsFollower) # session.query(Shout)
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id) # .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
# .filter(ShoutReactionsFollower.shout == Shout.id) # .filter(ShoutReactionsFollower.shout == Shout.id)
# .options(load_only(Shout.id)) # Exclude unnecessary columns
# .dicts()
# .all()
# ) # )
# shouts = list(shouts_query)
authors = set(session.execute(authors_query).scalars())
topics = set(session.execute(topics_query).scalars())
# shouts = set(session.execute(shouts_query).scalars())
# communities = session.query(Community).all() # communities = session.query(Community).all()
return { return {
"topics": list(topics), "topics": topics,
"authors": list(authors), "authors": authors,
# "shouts": list(shouts), # "shouts": shouts,
"communities": [{"id": 1, "name": "Дискурс", "slug": "discours"}], "communities": [{"id": 1, "name": "Дискурс", "slug": "discours"}],
} }
async def get_follows_by_user_id(user_id: str): async def get_follows_by_user_id(user_id: str):
if user_id: if user_id:
redis_key = f"user:{user_id}:follows" redis_key = f"user:{user_id}:follows"