This commit is contained in:
parent
d561deeb73
commit
8050a7e828
|
@ -380,14 +380,11 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||||
q = apply_reaction_filters(by, q)
|
q = apply_reaction_filters(by, q)
|
||||||
q = q.where(Reaction.deleted_at.is_(None))
|
q = q.where(Reaction.deleted_at.is_(None))
|
||||||
|
|
||||||
# order by
|
|
||||||
order_value = by.get("sort", "-created_at")
|
|
||||||
order_way = desc if order_value.startswith("-") else asc
|
|
||||||
order_field = order_value.replace("-", "")
|
|
||||||
# group by
|
# group by
|
||||||
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.created_at, Reaction[order_field]).order_by(
|
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.id)
|
||||||
order_way(order_field)
|
|
||||||
)
|
# order by
|
||||||
|
q = q.order_by(desc("created_at"))
|
||||||
|
|
||||||
# pagination
|
# pagination
|
||||||
q = q.limit(limit).offset(offset)
|
q = q.limit(limit).offset(offset)
|
||||||
|
@ -409,8 +406,9 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||||
reactions.append(reaction)
|
reactions.append(reaction)
|
||||||
|
|
||||||
# sort if by stat is present
|
# sort if by stat is present
|
||||||
if by.get("stat"):
|
stat_sort = by.get("stat")
|
||||||
reactions = sorted(reactions, key=lambda r: r.stat.get(by["stat"]) or r.created_at, reverse=True)
|
if stat_sort:
|
||||||
|
reactions = sorted(reactions, key=lambda r: r.stat.get(stat_sort) or r.created_at, reverse=stat_sort.startswith("-"))
|
||||||
|
|
||||||
return reactions
|
return reactions
|
||||||
|
|
||||||
|
@ -422,10 +420,10 @@ def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[Shout]:
|
||||||
if author:
|
if author:
|
||||||
shouts = (
|
shouts = (
|
||||||
session.query(Shout)
|
session.query(Shout)
|
||||||
.join(Reaction)
|
.join(Reaction, Reaction.shout == Shout.id)
|
||||||
|
.options(joinedload(Reaction.created_by))
|
||||||
.filter(Reaction.created_by == follower_id)
|
.filter(Reaction.created_by == follower_id)
|
||||||
.filter(Reaction.created_at > author.last_seen)
|
.filter(Reaction.created_at > author.last_seen)
|
||||||
.options(joinedload(Reaction.created_by), joinedload(Reaction.shout))
|
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.all()
|
.all()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user