This commit is contained in:
@@ -8,19 +8,19 @@ from orm.shout import ShoutTopic, ShoutAuthor
|
||||
|
||||
|
||||
def add_topic_stat_columns(q):
|
||||
aliased_shout_author = aliased(ShoutAuthor)
|
||||
aliased_topic_follower = aliased(TopicFollower)
|
||||
|
||||
aliased_shout_authors = aliased(ShoutAuthor)
|
||||
aliased_topic_followers = aliased(TopicFollower)
|
||||
aliased_topic = aliased(Topic)
|
||||
q = (
|
||||
q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic)
|
||||
q.outerjoin(ShoutTopic, aliased_topic.id == ShoutTopic.topic)
|
||||
.add_columns(func.count(distinct(ShoutTopic.shout)).label('shouts_stat'))
|
||||
.outerjoin(aliased_shout_author, ShoutTopic.shout == aliased_shout_author.shout)
|
||||
.add_columns(func.count(distinct(aliased_shout_author.author)).label('authors_stat'))
|
||||
.outerjoin(aliased_topic_follower, aliased_topic_follower.topic == Topic.id)
|
||||
.add_columns(func.count(distinct(aliased_topic_follower.follower)).label('followers_stat'))
|
||||
.outerjoin(aliased_shout_authors, ShoutTopic.shout == aliased_shout_authors.shout)
|
||||
.add_columns(func.count(distinct(aliased_shout_authors.author)).label('authors_stat'))
|
||||
.outerjoin(aliased_topic_followers, aliased_topic_followers.topic == aliased_topic.id)
|
||||
.add_columns(func.count(distinct(aliased_topic_followers.follower)).label('followers_stat'))
|
||||
)
|
||||
|
||||
q = q.group_by(Topic.id)
|
||||
q = q.group_by(aliased_topic.id)
|
||||
|
||||
return q
|
||||
|
||||
@@ -28,16 +28,17 @@ def add_topic_stat_columns(q):
|
||||
def add_author_stat_columns(q):
|
||||
aliased_author_followers = aliased(AuthorFollower)
|
||||
aliased_author_authors = aliased(AuthorFollower)
|
||||
aliased_author = aliased(Author)
|
||||
q = (
|
||||
q.outerjoin(ShoutAuthor, Author.id == ShoutAuthor.author)
|
||||
q.outerjoin(ShoutAuthor, aliased_author.id == ShoutAuthor.author)
|
||||
.add_columns(func.count(distinct(ShoutAuthor.shout)).label('shouts_stat'))
|
||||
.outerjoin(aliased_author_authors, AuthorFollower.follower == Author.id)
|
||||
.outerjoin(aliased_author_authors, AuthorFollower.follower == aliased_author.id)
|
||||
.add_columns(func.count(distinct(aliased_author_authors.author)).label('authors_stat'))
|
||||
.outerjoin(aliased_author_followers, AuthorFollower.author == Author.id)
|
||||
.outerjoin(aliased_author_followers, AuthorFollower.author == aliased_author.id)
|
||||
.add_columns(func.count(distinct(aliased_author_followers.follower)).label('followers_stat'))
|
||||
)
|
||||
|
||||
q = q.group_by(Author.id)
|
||||
q = q.group_by(aliased_author.id)
|
||||
|
||||
return q
|
||||
|
||||
|
Reference in New Issue
Block a user