sort-fix
All checks were successful
Deploy on push / deploy (push) Successful in 25s

This commit is contained in:
Untone 2024-02-26 20:07:42 +03:00
parent 02b504cc4f
commit be27e7306c

View File

@ -378,7 +378,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
# pagination # pagination
q = q.limit(limit).offset(offset) q = q.limit(limit).offset(offset)
reactions = [] reactions = set()
with local_session() as session: with local_session() as session:
result_rows = session.execute(q) result_rows = session.execute(q)
for [ for [
@ -398,16 +398,14 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
'reacted': reacted_stat, 'reacted': reacted_stat,
'commented': commented_stat, 'commented': commented_stat,
} }
reactions.append(reaction) # Используем список для хранения реакций reactions.add(reaction) # Используем список для хранения реакций
# sort if by stat is present # sort
stat_sort = by.get('stat') reactions = sorted(
if stat_sort: list(reactions),
reactions = sorted( key=lambda r: r.stat.get(by.get('stat')) or r.created_at,
reactions, reverse=by.get('stat', '').startswith('-'),
key=lambda r: r.stat.get(stat_sort) or r.created_at, )
reverse=stat_sort.startswith('-'),
)
return reactions return reactions