This commit is contained in:
parent
26c12b2aad
commit
2e635abe5e
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from sqlalchemy import desc, select, or_, and_
|
from sqlalchemy import select, or_, and_, text
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy_searchable import search
|
from sqlalchemy_searchable import search
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ def load_authors_by(_, _info, by, limit, offset):
|
||||||
q = q.filter(Author.created_at > before)
|
q = q.filter(Author.created_at > before)
|
||||||
|
|
||||||
order = by.get('order')
|
order = by.get('order')
|
||||||
if order == 'followers' or order == 'shouts':
|
if order in ['likes', 'shouts', 'followers']:
|
||||||
q = q.order_by(desc(f'{order}_stat'))
|
q = q.order_by(text(f'{order}_stat'))
|
||||||
|
|
||||||
q = q.limit(limit).offset(offset)
|
q = q.limit(limit).offset(offset)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def add_reaction_stat_columns(q, aliased_reaction):
|
||||||
(aliased_reaction.kind != str(ReactionKind.COMMENT.value), None),
|
(aliased_reaction.kind != str(ReactionKind.COMMENT.value), None),
|
||||||
else_=aliased_reaction.created_at,
|
else_=aliased_reaction.created_at,
|
||||||
)
|
)
|
||||||
).label('last_comment'),
|
).label('last_comment_stat'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
@ -445,7 +445,7 @@ async def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[S
|
||||||
|
|
||||||
# Sort shouts by the `last_comment` field
|
# Sort shouts by the `last_comment` field
|
||||||
combined_query = (
|
combined_query = (
|
||||||
union(q1, q2).order_by(desc('last_comment')).limit(limit).offset(offset)
|
union(q1, q2).order_by(desc('last_comment_stat')).limit(limit).offset(offset)
|
||||||
)
|
)
|
||||||
|
|
||||||
results = session.execute(combined_query).scalars()
|
results = session.execute(combined_query).scalars()
|
||||||
|
|
|
@ -144,9 +144,9 @@ async def load_shouts_by(_, _info, options):
|
||||||
|
|
||||||
# order
|
# order
|
||||||
order_by = Shout.featured_at if filters.get('featured') else Shout.published_at
|
order_by = Shout.featured_at if filters.get('featured') else Shout.published_at
|
||||||
order_by_str = options.get('order_by')
|
order_str = options.get('order_by')
|
||||||
if order_by_str:
|
if order_str in ['likes', 'shouts', 'followers', 'comments', 'last_comment']:
|
||||||
order_by = text(order_by_str)
|
q = q.order_by(text(f'{order_str}_stat'))
|
||||||
query_order_by = (
|
query_order_by = (
|
||||||
desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user