aliased-revert
This commit is contained in:
parent
cc16163673
commit
4d992f1b60
|
@ -357,26 +357,26 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
|||
aliased_reaction = aliased(Reaction)
|
||||
q = (
|
||||
select(aliased_reaction, Author, Shout)
|
||||
.select_from(aliased_reaction)
|
||||
.select_from(Reaction)
|
||||
.join(Author, aliased_reaction.created_by == Author.id)
|
||||
.join(Shout, aliased_reaction.shout == Shout.id)
|
||||
)
|
||||
|
||||
# calculate counters
|
||||
aliased_reaction_counters = aliased(Reaction)
|
||||
q = add_reaction_stat_columns(q, aliased_reaction_counters)
|
||||
aliased_reaction = aliased(Reaction)
|
||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
||||
|
||||
# filter
|
||||
q = apply_reaction_filters(by, q)
|
||||
q = q.where(aliased_reaction.deleted_at.is_(None))
|
||||
q = q.where(Reaction.deleted_at.is_(None))
|
||||
|
||||
# group by
|
||||
q = q.group_by(aliased_reaction.id, Author.id, Shout.id, aliased_reaction_counters.id)
|
||||
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.id)
|
||||
|
||||
# order by
|
||||
order_stat = by.get('sort', '') # 'like' | 'dislike' | 'created_at' | '-created_at'
|
||||
order_fn = asc if order_stat.startswith('-') else desc
|
||||
order_field = aliased_reaction.created_at if not order_stat else f'{order_stat}s_stat'
|
||||
order_field = Reaction.created_at if not order_stat else f'{order_stat}s_stat'
|
||||
q = q.order_by(order_fn(order_field))
|
||||
|
||||
# pagination
|
||||
|
|
Loading…
Reference in New Issue
Block a user