query-fix5
All checks were successful
Deploy to core / deploy (push) Successful in 2m40s

This commit is contained in:
Untone 2024-02-21 21:53:11 +03:00
parent f49fb2d01d
commit da33ae92a9

View File

@ -93,24 +93,17 @@ def query_follows(user_id: str):
if isinstance(author, Author): if isinstance(author, Author):
author_id = author.id author_id = author.id
authors_query = ( authors_query = (
select([ select(Author)
Author.name,
Author.id,
Author.slug,
Author.pic,
Author.bio
])
.select_from(Author)
.join(AuthorFollower, AuthorFollower.follower == author_id) .join(AuthorFollower, AuthorFollower.follower == author_id)
.filter(AuthorFollower.author == Author.id) .filter(AuthorFollower.author == Author.id)
) )
authors = [ authors = [
{ {
'id': author_id, 'id': author.id,
'name': name, 'name': author.name,
'slug': slug, 'slug': author.slug,
'pic': pic, 'pic': author.pic,
'bio': bio, 'bio': author.bio,
'stat': { 'stat': {
'shouts': shouts_stat, 'shouts': shouts_stat,
'followers': followers_stat, 'followers': followers_stat,
@ -118,11 +111,7 @@ def query_follows(user_id: str):
}, },
} }
for ( for (
name, author,
author_id,
slug,
pic,
bio,
shouts_stat, shouts_stat,
followers_stat, followers_stat,
followings_stat, followings_stat,
@ -130,22 +119,16 @@ def query_follows(user_id: str):
] ]
topics_query = ( topics_query = (
select([ select(Topic)
Topic.title,
Topic.id,
Topic.slug,
Topic.body,
])
.select_from(Topic)
.join(TopicFollower, TopicFollower.follower == author_id) .join(TopicFollower, TopicFollower.follower == author_id)
.filter(TopicFollower.topic == Topic.id) .filter(TopicFollower.topic == Topic.id)
) )
topics = [ topics = [
{ {
'id': topic_id, 'id': topic.id,
'title': title, 'title': topic.title,
'slug': slug, 'slug': topic.slug,
'body': body, 'body': topic.body,
'stat': { 'stat': {
'shouts': shouts_stat, 'shouts': shouts_stat,
'authors': authors_stat, 'authors': authors_stat,
@ -153,17 +136,14 @@ def query_follows(user_id: str):
}, },
} }
for ( for (
title, topic,
topic_id,
slug,
body,
shouts_stat, shouts_stat,
authors_stat, authors_stat,
followers_stat, followers_stat,
) in session.execute(topics_query) ) in session.execute(topics_query)
] ]
# Include other queries (e.g., shouts_query) if needed # TODO: Include other queries (e.g., shouts_query) if needed
return { return {
'topics': topics, 'topics': topics,