cache-author-with-stat
All checks were successful
Deploy on push / deploy (push) Successful in 24s

This commit is contained in:
Untone 2024-02-27 14:53:13 +03:00
parent 8d058b4902
commit 564a8c10b7

View File

@ -58,11 +58,8 @@ def after_shouts_update(mapper, connection, shout: Shout):
.where(ShoutAuthor.shout == shout.id) # Filter by shout.id .where(ShoutAuthor.shout == shout.id) # Filter by shout.id
) )
# Execute the query for author_with_stat in get_with_stat(authors_query):
authors = get_with_stat(authors_query) asyncio.create_task(update_author_cache(author_with_stat.dict()))
for author in authors:
asyncio.create_task(update_author_cache(author.dict()))
@event.listens_for(Reaction, 'after_insert') @event.listens_for(Reaction, 'after_insert')
@ -86,10 +83,9 @@ def after_reaction_insert(mapper, connection, reaction: Reaction):
) )
.select_from(replied_author_subquery.subquery()) .select_from(replied_author_subquery.subquery())
) )
authors = get_with_stat(author_query)
for author in authors: for author_with_stat in get_with_stat(author_query):
asyncio.create_task(update_author_cache(author.dict())) asyncio.create_task(update_author_cache(author_with_stat.dict()))
shout = connection.execute(select(Shout).select_from(Shout).where(Shout.id == reaction.shout)).first() shout = connection.execute(select(Shout).select_from(Shout).where(Shout.id == reaction.shout)).first()
if shout: if shout:
@ -101,7 +97,9 @@ def after_reaction_insert(mapper, connection, reaction: Reaction):
@event.listens_for(Author, 'after_insert') @event.listens_for(Author, 'after_insert')
@event.listens_for(Author, 'after_update') @event.listens_for(Author, 'after_update')
def after_author_update(mapper, connection, author: Author): def after_author_update(mapper, connection, author: Author):
asyncio.create_task(update_author_cache(author.dict())) q = select(Author).where(Author.id == author.id)
[author_with_stat] = get_with_stat(q)
asyncio.create_task(update_author_cache(author_with_stat.dict()))
@event.listens_for(TopicFollower, 'after_insert') @event.listens_for(TopicFollower, 'after_insert')