query-fix
This commit is contained in:
parent
6bac6b737e
commit
cdb9d31fa4
|
@ -380,27 +380,29 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||||
q = q.where(Reaction.deleted_at.is_(None))
|
q = q.where(Reaction.deleted_at.is_(None))
|
||||||
q = q.limit(limit).offset(offset)
|
q = q.limit(limit).offset(offset)
|
||||||
reactions = []
|
reactions = []
|
||||||
for [
|
with local_session() as session:
|
||||||
reaction,
|
result_rows = session.execute(q)
|
||||||
author,
|
for [
|
||||||
shout,
|
reaction,
|
||||||
reacted_stat,
|
author,
|
||||||
commented_stat,
|
shout,
|
||||||
rating_stat,
|
reacted_stat,
|
||||||
] in local_session().execute(q):
|
commented_stat,
|
||||||
reaction.created_by = author
|
rating_stat,
|
||||||
reaction.shout = shout
|
] in result_rows:
|
||||||
reaction.stat = {
|
reaction.created_by = author
|
||||||
"rating": rating_stat,
|
reaction.shout = shout
|
||||||
"commented": commented_stat,
|
reaction.stat = {
|
||||||
"reacted": reacted_stat,
|
"rating": rating_stat,
|
||||||
}
|
"commented": commented_stat,
|
||||||
reaction.kind = reaction.kind.name
|
"reacted": reacted_stat,
|
||||||
reactions.append(reaction)
|
}
|
||||||
|
reaction.kind = reaction.kind.name
|
||||||
|
reactions.append(reaction)
|
||||||
|
|
||||||
# sort if by stat is present
|
# sort if by stat is present
|
||||||
if by.get("stat"):
|
if by.get("stat"):
|
||||||
reactions = sorted(reactions, key=lambda r: r.stat.get(by["stat"]) or r.created_at)
|
reactions = sorted(reactions, key=lambda r: r.stat.get(by["stat"]) or r.created_at)
|
||||||
|
|
||||||
return reactions
|
return reactions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user