This commit is contained in:
parent
c90b0bd994
commit
263ceac5a3
|
@ -76,7 +76,9 @@ async def get_shout(_, _info, slug=None, shout_id=None):
|
||||||
'rating': int(likes_stat or 0) - int(dislikes_stat or 0),
|
'rating': int(likes_stat or 0) - int(dislikes_stat or 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
|
for author_caption in (
|
||||||
|
session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug)
|
||||||
|
):
|
||||||
for author in shout.authors:
|
for author in shout.authors:
|
||||||
if author.id == author_caption.author:
|
if author.id == author_caption.author:
|
||||||
author.caption = author_caption.caption
|
author.caption = author_caption.caption
|
||||||
|
@ -97,7 +99,9 @@ async def get_shout(_, _info, slug=None, shout_id=None):
|
||||||
shout.main_topic = main_topic[0]
|
shout.main_topic = main_topic[0]
|
||||||
return shout
|
return shout
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=404, detail=f'shout {slug or shout_id} not found')
|
raise HTTPException(
|
||||||
|
status_code=404, detail=f'shout {slug or shout_id} not found'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@query.field('load_shouts_by')
|
@query.field('load_shouts_by')
|
||||||
|
@ -143,7 +147,9 @@ async def load_shouts_by(_, _info, options):
|
||||||
|
|
||||||
# order
|
# order
|
||||||
order_by = options.get('order_by', Shout.published_at)
|
order_by = options.get('order_by', Shout.published_at)
|
||||||
query_order_by = desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
query_order_by = (
|
||||||
|
desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
||||||
|
)
|
||||||
q = q.order_by(nulls_last(query_order_by))
|
q = q.order_by(nulls_last(query_order_by))
|
||||||
|
|
||||||
# limit offset
|
# limit offset
|
||||||
|
@ -236,15 +242,20 @@ async def load_shouts_feed(_, info, options):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
reader = session.query(Author).filter(Author.user == user_id).first()
|
reader = session.query(Author).filter(Author.user == user_id).first()
|
||||||
if reader:
|
if reader:
|
||||||
reader_followed_authors = select(AuthorFollower.author).where(AuthorFollower.follower == reader.id)
|
reader_followed_authors = select(AuthorFollower.author).where(
|
||||||
reader_followed_topics = select(TopicFollower.topic).where(TopicFollower.follower == reader.id)
|
AuthorFollower.follower == reader.id
|
||||||
|
)
|
||||||
|
reader_followed_topics = select(TopicFollower.topic).where(
|
||||||
|
TopicFollower.follower == reader.id
|
||||||
|
)
|
||||||
|
|
||||||
subquery = (
|
subquery = (
|
||||||
select(Shout.id)
|
select(Shout.id)
|
||||||
.where(Shout.id == ShoutAuthor.shout)
|
.where(Shout.id == ShoutAuthor.shout)
|
||||||
.where(Shout.id == ShoutTopic.shout)
|
.where(Shout.id == ShoutTopic.shout)
|
||||||
.where(
|
.where(
|
||||||
(ShoutAuthor.author.in_(reader_followed_authors)) | (ShoutTopic.topic.in_(reader_followed_topics))
|
(ShoutAuthor.author.in_(reader_followed_authors))
|
||||||
|
| (ShoutTopic.topic.in_(reader_followed_topics))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -269,15 +280,24 @@ async def load_shouts_feed(_, info, options):
|
||||||
|
|
||||||
order_by = options.get('order_by', Shout.published_at)
|
order_by = options.get('order_by', Shout.published_at)
|
||||||
|
|
||||||
query_order_by = desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
query_order_by = (
|
||||||
|
desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
|
||||||
|
)
|
||||||
offset = options.get('offset', 0)
|
offset = options.get('offset', 0)
|
||||||
limit = options.get('limit', 10)
|
limit = options.get('limit', 10)
|
||||||
|
|
||||||
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
|
q = (
|
||||||
|
q.group_by(Shout.id)
|
||||||
|
.order_by(nulls_last(query_order_by))
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset)
|
||||||
|
)
|
||||||
|
|
||||||
# print(q.compile(compile_kwargs={"literal_binds": True}))
|
# print(q.compile(compile_kwargs={"literal_binds": True}))
|
||||||
|
|
||||||
for [shout, reacted_stat, commented_stat, _last_comment] in session.execute(q).unique():
|
for [shout, reacted_stat, commented_stat, _last_comment] in session.execute(
|
||||||
|
q
|
||||||
|
).unique():
|
||||||
main_topic = (
|
main_topic = (
|
||||||
session.query(Topic.slug)
|
session.query(Topic.slug)
|
||||||
.join(
|
.join(
|
||||||
|
@ -308,7 +328,7 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
||||||
if text and len(text) > 2:
|
if text and len(text) > 2:
|
||||||
results = await SearchService.search(text, limit, offset)
|
results = await SearchService.search(text, limit, offset)
|
||||||
results_dict = {r['slug']: r for r in results}
|
results_dict = {r['slug']: r for r in results}
|
||||||
# print(results_dict)
|
found_keys = results_dict.keys()
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
select(Shout)
|
select(Shout)
|
||||||
|
@ -316,7 +336,12 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
||||||
joinedload(Shout.authors),
|
joinedload(Shout.authors),
|
||||||
joinedload(Shout.topics),
|
joinedload(Shout.topics),
|
||||||
)
|
)
|
||||||
.where(and_(Shout.deleted_at.is_(None), Shout.slug.in_(results_dict.keys())))
|
.where(
|
||||||
|
and_(
|
||||||
|
Shout.deleted_at.is_(None),
|
||||||
|
Shout.id.in_(found_keys),
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
shouts_data = []
|
shouts_data = []
|
||||||
|
@ -378,7 +403,9 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0):
|
||||||
and_(
|
and_(
|
||||||
Reaction.shout == Shout.id,
|
Reaction.shout == Shout.id,
|
||||||
Reaction.replyTo.is_(None),
|
Reaction.replyTo.is_(None),
|
||||||
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]),
|
Reaction.kind.in_(
|
||||||
|
[ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.outerjoin(Author, Author.user == bindparam('user_id'))
|
.outerjoin(Author, Author.user == bindparam('user_id'))
|
||||||
|
@ -447,7 +474,9 @@ async def load_shouts_random_top(_, _info, options):
|
||||||
|
|
||||||
aliased_reaction = aliased(Reaction)
|
aliased_reaction = aliased(Reaction)
|
||||||
|
|
||||||
subquery = select(Shout.id).outerjoin(aliased_reaction).where(Shout.deleted_at.is_(None))
|
subquery = (
|
||||||
|
select(Shout.id).outerjoin(aliased_reaction).where(Shout.deleted_at.is_(None))
|
||||||
|
)
|
||||||
|
|
||||||
subquery = apply_filters(subquery, options.get('filters', {}))
|
subquery = apply_filters(subquery, options.get('filters', {}))
|
||||||
subquery = subquery.group_by(Shout.id).order_by(
|
subquery = subquery.group_by(Shout.id).order_by(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user