compound-fix
All checks were successful
Deploy on push / deploy (push) Successful in 28s

This commit is contained in:
Untone 2024-05-18 17:31:45 +03:00
parent b7dbaa6e73
commit 0d618116e1

View File

@ -1,8 +1,7 @@
import asyncio import asyncio
import json import json
from sqlalchemy import event, select, union from sqlalchemy import event, select
from sqlalchemy.orm import aliased
from orm.author import Author, AuthorFollower from orm.author import Author, AuthorFollower
from orm.reaction import Reaction from orm.reaction import Reaction
@ -75,19 +74,19 @@ def after_shout_update(_mapper, _connection, shout: Shout):
def after_reaction_update(mapper, connection, reaction: Reaction): def after_reaction_update(mapper, connection, reaction: Reaction):
logger.info("after reaction update") logger.info("after reaction update")
try: try:
# reaction author
author_subquery = select(Author).where(Author.id == reaction.created_by) author_subquery = select(Author).where(Author.id == reaction.created_by)
[author_with_stat] = get_with_stat(author_subquery)
if isinstance(author_with_stat, Author):
asyncio.create_task(cache_author(author_with_stat.dict()))
# reaction repliers
replied_author_subquery = ( replied_author_subquery = (
select(Author) select(Author)
.join(Reaction, Author.id == Reaction.created_by) .join(Reaction, Author.id == Reaction.created_by)
.where(Reaction.id == reaction.reply_to) .where(Reaction.id == reaction.reply_to)
) )
authors_with_stat = get_with_stat(replied_author_subquery)
author_aliased_query = aliased(union(author_subquery, replied_author_subquery))
# Get authors with stat
authors_with_stat = get_with_stat(author_aliased_query)
# Cache authors
for author_with_stat in authors_with_stat: for author_with_stat in authors_with_stat:
asyncio.create_task(cache_author(author_with_stat.dict())) asyncio.create_task(cache_author(author_with_stat.dict()))