Merge remote-tracking branch 'origin/main' into storages-to-qeuries
This commit is contained in:
@@ -205,16 +205,6 @@ async def delete_reaction(_, info, rid):
|
||||
session.commit()
|
||||
return {}
|
||||
|
||||
|
||||
def map_result_item(result_item):
|
||||
[user, shout, reaction] = result_item
|
||||
print(reaction)
|
||||
reaction.createdBy = user
|
||||
reaction.shout = shout
|
||||
reaction.replyTo = reaction
|
||||
return reaction
|
||||
|
||||
|
||||
@query.field("loadReactionsBy")
|
||||
async def load_reactions_by(_, _info, by, limit=50, offset=0):
|
||||
"""
|
||||
@@ -235,15 +225,12 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0):
|
||||
|
||||
CreatedByUser = aliased(User)
|
||||
ReactedShout = aliased(Shout)
|
||||
RepliedReaction = aliased(Reaction)
|
||||
q = select(
|
||||
Reaction, CreatedByUser, ReactedShout, RepliedReaction
|
||||
Reaction, CreatedByUser, ReactedShout
|
||||
).join(
|
||||
CreatedByUser, Reaction.createdBy == CreatedByUser.slug
|
||||
).join(
|
||||
ReactedShout, Reaction.shout == ReactedShout.slug
|
||||
).join(
|
||||
RepliedReaction, Reaction.replyTo == RepliedReaction.id
|
||||
)
|
||||
|
||||
if by.get("shout"):
|
||||
@@ -261,23 +248,26 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0):
|
||||
if by.get("days"):
|
||||
after = datetime.now(tz=timezone.utc) - timedelta(days=int(by["days"]) or 30)
|
||||
q = q.filter(Reaction.createdAt > after)
|
||||
|
||||
order_way = asc if by.get("sort", "").startswith("-") else desc
|
||||
order_field = by.get("sort") or Reaction.createdAt
|
||||
|
||||
q = q.group_by(
|
||||
Reaction.id, CreatedByUser.id, ReactedShout.id
|
||||
).order_by(
|
||||
order_way(order_field)
|
||||
)
|
||||
|
||||
q = calc_reactions(q)
|
||||
|
||||
q = q.where(Reaction.deletedAt.is_(None))
|
||||
q = q.limit(limit).offset(offset)
|
||||
reactions = []
|
||||
|
||||
with local_session() as session:
|
||||
for [
|
||||
[reaction, rating, commented, reacted], shout, reply
|
||||
] in list(map(map_result_item, session.execute(q))):
|
||||
for [reaction, user, shout, rating, commented, reacted] in session.execute(q):
|
||||
reaction.createdBy = user
|
||||
reaction.shout = shout
|
||||
reaction.replyTo = reply
|
||||
reaction.stat = {
|
||||
"rating": rating,
|
||||
"commented": commented,
|
||||
|
Reference in New Issue
Block a user