This commit is contained in:
parent
9812b308b3
commit
4320c9674c
|
@ -3,6 +3,7 @@ from typing import List
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
from orm.author import Author, AuthorFollower
|
from orm.author import Author, AuthorFollower
|
||||||
from orm.community import Community
|
from orm.community import Community
|
||||||
|
@ -103,12 +104,13 @@ async def get_my_followed(_, info):
|
||||||
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 author:
|
if author:
|
||||||
authors_query = (
|
aliased_authors = aliased(Author)
|
||||||
select(Author)
|
|
||||||
.join(AuthorFollower, AuthorFollower.follower == Author.id)
|
|
||||||
.filter(AuthorFollower.follower == author.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
authors_query = (
|
||||||
|
session.query(aliased_authors)
|
||||||
|
.join(AuthorFollower, AuthorFollower.follower == author.id)
|
||||||
|
.filter(AuthorFollower.author == aliased_authors.id)
|
||||||
|
)
|
||||||
topics_query = select(Topic).join(TopicFollower, TopicFollower.follower == Author.id)
|
topics_query = select(Topic).join(TopicFollower, TopicFollower.follower == Author.id)
|
||||||
|
|
||||||
for [author] in session.execute(authors_query):
|
for [author] in session.execute(authors_query):
|
||||||
|
|
|
@ -13,10 +13,9 @@ async def followed_topics(follower_id):
|
||||||
q = select(Author)
|
q = select(Author)
|
||||||
q = add_topic_stat_columns(q)
|
q = add_topic_stat_columns(q)
|
||||||
q = q.join(TopicFollower, TopicFollower.author == Author.id).where(TopicFollower.follower == follower_id)
|
q = q.join(TopicFollower, TopicFollower.author == Author.id).where(TopicFollower.follower == follower_id)
|
||||||
# Pass the query to the get_authors_from_query function and return the results
|
# Pass the query to the get_topics_from_query function and return the results
|
||||||
return get_topics_from_query(q)
|
return get_topics_from_query(q)
|
||||||
|
|
||||||
|
|
||||||
def add_topic_stat_columns(q):
|
def add_topic_stat_columns(q):
|
||||||
aliased_shout_author = aliased(ShoutAuthor)
|
aliased_shout_author = aliased(ShoutAuthor)
|
||||||
aliased_topic_follower = aliased(TopicFollower)
|
aliased_topic_follower = aliased(TopicFollower)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user