resolvers-fix

This commit is contained in:
Untone 2023-12-02 09:25:08 +03:00
parent 5fe27f9c0c
commit 34940178ad
2 changed files with 12 additions and 3 deletions

View File

@ -149,15 +149,24 @@ async def load_shouts_by(_, info, options):
.where(Shout.deleted_at.is_(None))
)
# counters
q = add_stat_columns(q)
# filters
q = apply_filters(q, options.get("filters", {}))
# group
q = q.group_by(Shout.id, Author.user)
# order
order_by = options.get("order_by", Shout.published_at)
query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
q = q.order_by(nulls_last(query_order_by))
# limit offset
offset = options.get("offset", 0)
limit = options.get("limit", 10)
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
q = q.limit(limit).offset(offset)
shouts = []
shouts_map = {}

View File

@ -26,7 +26,7 @@ def add_topic_stat_columns(q):
.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.user)).label("authors_stat"))
.add_columns(func.count(distinct(aliased_shout_author.author)).label("authors_stat"))
.outerjoin(aliased_topic_follower)
.add_columns(func.count(distinct(aliased_topic_follower.follower)).label("followers_stat"))