This commit is contained in:
parent
1eac614e35
commit
784f790b83
|
@ -264,7 +264,11 @@ async def get_author_follows(
|
||||||
) -> List[Author]:
|
) -> List[Author]:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
if not user and (author_id or slug):
|
if not user and (author_id or slug):
|
||||||
user = session.query(Author.user).where(or_(Author.id == author_id, Author.slug == slug)).first()
|
user = (
|
||||||
|
session.query(Author.user)
|
||||||
|
.where(or_(Author.id == author_id, Author.slug == slug))
|
||||||
|
.first()
|
||||||
|
)
|
||||||
if user:
|
if user:
|
||||||
follows = await get_follows_by_user_id(user)
|
follows = await get_follows_by_user_id(user)
|
||||||
return follows
|
return follows
|
||||||
|
|
|
@ -98,7 +98,13 @@ 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(column('name'), column('id'), column('slug'), column('pic'), column('bio'))
|
select(
|
||||||
|
column('name'),
|
||||||
|
column('id'),
|
||||||
|
column('slug'),
|
||||||
|
column('pic'),
|
||||||
|
column('bio'),
|
||||||
|
)
|
||||||
.select_from(Author)
|
.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)
|
||||||
|
@ -114,29 +120,45 @@ def query_follows(user_id: str):
|
||||||
topics_query = add_topic_stat_columns(topics_query)
|
topics_query = add_topic_stat_columns(topics_query)
|
||||||
|
|
||||||
# Convert query results to lists of dictionaries
|
# Convert query results to lists of dictionaries
|
||||||
authors = [{
|
authors = [
|
||||||
'id': author.id,
|
{
|
||||||
'name': author.name,
|
'id': author.id,
|
||||||
'slug': author.slug,
|
'name': author.name,
|
||||||
'pic': author.pic,
|
'slug': author.slug,
|
||||||
'bio': author.bio,
|
'pic': author.pic,
|
||||||
'stat': {
|
'bio': author.bio,
|
||||||
'shouts': shouts_stat,
|
'stat': {
|
||||||
'followers': followers_stat,
|
'shouts': shouts_stat,
|
||||||
'followings': followings_stat,
|
'followers': followers_stat,
|
||||||
}
|
'followings': followings_stat,
|
||||||
} for [author, shouts_stat, followers_stat, followings_stat] in session.execute(authors_query)]
|
},
|
||||||
topics = [{
|
}
|
||||||
'id': topic.id,
|
for [
|
||||||
'title': topic.title,
|
author,
|
||||||
'slug': topic.slug,
|
shouts_stat,
|
||||||
'body': topic.body,
|
followers_stat,
|
||||||
'stat': {
|
followings_stat,
|
||||||
'shouts': shouts_stat,
|
] in session.execute(authors_query)
|
||||||
'authors': authors_stat,
|
]
|
||||||
'followers': followers_stat,
|
topics = [
|
||||||
}
|
{
|
||||||
} for [topic, shouts_stat, authors_stat, followers_stat] in session.execute(topics_query)]
|
'id': topic.id,
|
||||||
|
'title': topic.title,
|
||||||
|
'slug': topic.slug,
|
||||||
|
'body': topic.body,
|
||||||
|
'stat': {
|
||||||
|
'shouts': shouts_stat,
|
||||||
|
'authors': authors_stat,
|
||||||
|
'followers': followers_stat,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for [
|
||||||
|
topic,
|
||||||
|
shouts_stat,
|
||||||
|
authors_stat,
|
||||||
|
followers_stat,
|
||||||
|
] in session.execute(topics_query)
|
||||||
|
]
|
||||||
# shouts_query = (
|
# shouts_query = (
|
||||||
# session.query(Shout)
|
# session.query(Shout)
|
||||||
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
|
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
|
||||||
|
|
|
@ -103,14 +103,18 @@ async def handle_author_follower_change(connection, author_id, follower_id, is_i
|
||||||
).first()
|
).first()
|
||||||
if follower and author:
|
if follower and author:
|
||||||
await update_follows_for_user(
|
await update_follows_for_user(
|
||||||
connection, follower.user, 'author', {
|
connection,
|
||||||
"id": author.id,
|
follower.user,
|
||||||
"name": author.name,
|
'author',
|
||||||
"slug": author.slug,
|
{
|
||||||
"pic": author.pic,
|
'id': author.id,
|
||||||
"bio": author.bio,
|
'name': author.name,
|
||||||
"stat": author.stat
|
'slug': author.slug,
|
||||||
}, is_insert
|
'pic': author.pic,
|
||||||
|
'bio': author.bio,
|
||||||
|
'stat': author.stat,
|
||||||
|
},
|
||||||
|
is_insert,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,17 +136,23 @@ async def handle_topic_follower_change(connection, topic_id, follower_id, is_ins
|
||||||
).first()
|
).first()
|
||||||
if follower and topic:
|
if follower and topic:
|
||||||
await update_follows_for_user(
|
await update_follows_for_user(
|
||||||
connection, follower.user, 'topic', {
|
connection,
|
||||||
"id": topic.id,
|
follower.user,
|
||||||
"title": topic.title,
|
'topic',
|
||||||
"slug": topic.slug,
|
{
|
||||||
"body": topic.body,
|
'id': topic.id,
|
||||||
"stat": topic.stat
|
'title': topic.title,
|
||||||
}, is_insert
|
'slug': topic.slug,
|
||||||
|
'body': topic.body,
|
||||||
|
'stat': topic.stat,
|
||||||
|
},
|
||||||
|
is_insert,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
BATCH_SIZE = 33
|
BATCH_SIZE = 33
|
||||||
|
|
||||||
|
|
||||||
class FollowsCached:
|
class FollowsCached:
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
|
|
||||||
|
@ -175,7 +185,7 @@ class FollowsCached:
|
||||||
'slug': author.slug,
|
'slug': author.slug,
|
||||||
'pic': author.pic,
|
'pic': author.pic,
|
||||||
'bio': author.bio,
|
'bio': author.bio,
|
||||||
'stat': author.stat
|
'stat': author.stat,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user