This commit is contained in:
parent
71db929fa4
commit
d0c1f33227
|
@ -1,6 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
from sqlalchemy import and_, case, desc, func, select, asc
|
||||||
from sqlalchemy import and_, asc, case, desc, func, select
|
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
|
@ -17,19 +16,45 @@ from services.notify import notify_reaction
|
||||||
from services.schema import mutation, query
|
from services.schema import mutation, query
|
||||||
|
|
||||||
|
|
||||||
def add_reaction_stat_columns(q, aliased_reaction):
|
def query_reactions():
|
||||||
"""
|
"""
|
||||||
Добавляет статистические колонки к запросу реакций.
|
Base query for fetching reactions with associated authors and shouts.
|
||||||
|
|
||||||
:param q: SQL-запрос для реакций.
|
:return: Base query.
|
||||||
:param aliased_reaction: Алиас для таблицы реакций.
|
|
||||||
:return: Запрос с добавленными колонками статистики.
|
|
||||||
"""
|
"""
|
||||||
# Присоединение реакций и добавление статистических колонок
|
return (
|
||||||
q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
|
select(
|
||||||
# Подсчет комментариев
|
Reaction,
|
||||||
func.count().filter(aliased_reaction.kind == ReactionKind.COMMENT.value).label("comments_stat"),
|
Author,
|
||||||
# Вычисление рейтинга как разница между лайками и дизлайками
|
Shout,
|
||||||
|
)
|
||||||
|
.select_from(Reaction)
|
||||||
|
.join(Author, Reaction.created_by == Author.id)
|
||||||
|
.join(Shout, Reaction.shout == Shout.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_reaction_stat_columns(q):
|
||||||
|
"""
|
||||||
|
Add statistical columns to a reaction query.
|
||||||
|
|
||||||
|
:param q: SQL query for reactions.
|
||||||
|
:return: Query with added statistics columns.
|
||||||
|
"""
|
||||||
|
aliased_reaction = aliased(Reaction)
|
||||||
|
# Join reactions and add statistical columns
|
||||||
|
q = q.outerjoin(
|
||||||
|
aliased_reaction,
|
||||||
|
and_(
|
||||||
|
aliased_reaction.reply_to == Reaction.id,
|
||||||
|
aliased_reaction.deleted_at.is_(None),
|
||||||
|
),
|
||||||
|
).add_columns(
|
||||||
|
# Count unique comments
|
||||||
|
func.count(aliased_reaction.id)
|
||||||
|
.filter(aliased_reaction.kind == ReactionKind.COMMENT.value)
|
||||||
|
.label("comments_stat"),
|
||||||
|
# Calculate rating as the difference between likes and dislikes
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
|
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
|
||||||
|
@ -38,91 +63,110 @@ def add_reaction_stat_columns(q, aliased_reaction):
|
||||||
)
|
)
|
||||||
).label("rating_stat"),
|
).label("rating_stat"),
|
||||||
)
|
)
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
def get_reactions_with_stat(q, limit, offset):
|
||||||
|
"""
|
||||||
|
Execute the reaction query and retrieve reactions with statistics.
|
||||||
|
|
||||||
|
:param q: Query with reactions and statistics.
|
||||||
|
:param limit: Number of reactions to load.
|
||||||
|
:param offset: Pagination offset.
|
||||||
|
:return: List of reactions.
|
||||||
|
"""
|
||||||
|
q = q.limit(limit).offset(offset)
|
||||||
|
reactions = []
|
||||||
|
|
||||||
|
with local_session() as session:
|
||||||
|
result_rows = session.execute(q)
|
||||||
|
for reaction, author, shout, commented_stat, rating_stat in result_rows:
|
||||||
|
reaction.created_by = author
|
||||||
|
reaction.shout = shout
|
||||||
|
reaction.stat = {"rating": rating_stat, "comments": commented_stat}
|
||||||
|
reactions.append(reaction)
|
||||||
|
|
||||||
|
return reactions
|
||||||
|
|
||||||
|
|
||||||
def is_featured_author(session, author_id) -> bool:
|
def is_featured_author(session, author_id) -> bool:
|
||||||
"""
|
"""
|
||||||
Проверяет, есть ли у автора хотя бы одна опубликованная статья.
|
Check if an author has at least one featured article.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param author_id: Идентификатор автора.
|
:param author_id: Author ID.
|
||||||
:return: True, если у автора есть хотя бы одна опубликованная статья, иначе False.
|
:return: True if the author has a featured article, else False.
|
||||||
"""
|
"""
|
||||||
return (
|
return session.query(
|
||||||
session.query(Shout)
|
session.query(Shout).where(Shout.authors.any(id=author_id)).filter(Shout.featured_at.is_not(None)).exists()
|
||||||
.where(Shout.authors.any(id=author_id))
|
).scalar()
|
||||||
.filter(and_(Shout.featured_at.is_not(None), Shout.deleted_at.is_(None)))
|
|
||||||
.count()
|
|
||||||
> 0
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def check_to_feature(session, approver_id, reaction) -> bool:
|
def check_to_feature(session, approver_id, reaction) -> bool:
|
||||||
"""
|
"""
|
||||||
Устанавливает публикацию в открытый доступ, если количество голосов превышает 4.
|
Make a shout featured if it receives more than 4 votes.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param approver_id: Идентификатор утверждающего автора.
|
:param approver_id: Approver author ID.
|
||||||
:param reaction: Объект реакции.
|
:param reaction: Reaction object.
|
||||||
:return: True, если нужно установить публикацию в открытый доступ, иначе False.
|
:return: True if shout should be featured, else False.
|
||||||
"""
|
"""
|
||||||
if not reaction.reply_to and is_positive(reaction.kind):
|
if not reaction.reply_to and is_positive(reaction.kind):
|
||||||
if is_featured_author(session, approver_id):
|
approvers = {approver_id}
|
||||||
approvers = [approver_id]
|
# Count the number of approvers
|
||||||
# Подсчет количества голосующих утверждающих
|
reacted_readers = (
|
||||||
reacted_readers = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
|
session.query(Reaction.created_by)
|
||||||
for reacted_reader in reacted_readers:
|
.filter(Reaction.shout == reaction.shout, is_positive(Reaction.kind), Reaction.deleted_at.is_(None))
|
||||||
if is_featured_author(session, reacted_reader.id):
|
.distinct()
|
||||||
approvers.append(reacted_reader.id)
|
)
|
||||||
if len(approvers) > 4:
|
|
||||||
return True
|
for reader_id in reacted_readers:
|
||||||
|
if is_featured_author(session, reader_id):
|
||||||
|
approvers.add(reader_id)
|
||||||
|
return len(approvers) > 4
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_to_unfeature(session, rejecter_id, reaction) -> bool:
|
def check_to_unfeature(session, rejecter_id, reaction) -> bool:
|
||||||
"""
|
"""
|
||||||
Убирает публикацию из открытого доступа, если 20% реакций негативные.
|
Unfeature a shout if 20% of reactions are negative.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param rejecter_id: Идентификатор отклоняющего автора.
|
:param rejecter_id: Rejecter author ID.
|
||||||
:param reaction: Объект реакции.
|
:param reaction: Reaction object.
|
||||||
:return: True, если нужно убрать публикацию из открытого доступа, иначе False.
|
:return: True if shout should be unfeatured, else False.
|
||||||
"""
|
"""
|
||||||
if not reaction.reply_to and is_negative(reaction.kind):
|
if not reaction.reply_to and is_negative(reaction.kind):
|
||||||
if is_featured_author(session, rejecter_id):
|
total_reactions = (
|
||||||
reactions = (
|
|
||||||
session.query(Reaction)
|
session.query(Reaction)
|
||||||
.where(
|
.filter(
|
||||||
and_(
|
Reaction.shout == reaction.shout, Reaction.kind.in_(RATING_REACTIONS), Reaction.deleted_at.is_(None)
|
||||||
Reaction.shout == reaction.shout,
|
|
||||||
Reaction.kind.in_(RATING_REACTIONS),
|
|
||||||
)
|
)
|
||||||
|
.count()
|
||||||
)
|
)
|
||||||
.all()
|
|
||||||
|
negative_reactions = (
|
||||||
|
session.query(Reaction)
|
||||||
|
.filter(Reaction.shout == reaction.shout, is_negative(Reaction.kind), Reaction.deleted_at.is_(None))
|
||||||
|
.count()
|
||||||
)
|
)
|
||||||
rejects = 0
|
|
||||||
for r in reactions:
|
return total_reactions > 0 and (negative_reactions / total_reactions) >= 0.2
|
||||||
approver = session.query(Author).filter(Author.id == r.created_by).first()
|
|
||||||
if is_featured_author(session, approver):
|
|
||||||
if is_negative(r.kind):
|
|
||||||
rejects += 1
|
|
||||||
if len(reactions) / rejects < 5:
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_featured(session, shout_id):
|
async def set_featured(session, shout_id):
|
||||||
"""
|
"""
|
||||||
Устанавливает публикацию в открытый доступ и обновляет роль автора.
|
Feature a shout and update the author's role.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param shout_id: Идентификатор публикации.
|
:param shout_id: Shout ID.
|
||||||
"""
|
"""
|
||||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
s = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
s.featured_at = int(time.time())
|
if s:
|
||||||
Shout.update(s, {"featured_at": int(time.time())})
|
current_time = int(time.time())
|
||||||
|
s.featured_at = current_time
|
||||||
|
session.commit()
|
||||||
author = session.query(Author).filter(Author.id == s.created_by).first()
|
author = session.query(Author).filter(Author.id == s.created_by).first()
|
||||||
if author:
|
if author:
|
||||||
await add_user_role(str(author.user))
|
await add_user_role(str(author.user))
|
||||||
|
@ -132,65 +176,54 @@ async def set_featured(session, shout_id):
|
||||||
|
|
||||||
def set_unfeatured(session, shout_id):
|
def set_unfeatured(session, shout_id):
|
||||||
"""
|
"""
|
||||||
Убирает публикацию из открытого доступа.
|
Unfeature a shout.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param shout_id: Идентификатор публикации.
|
:param shout_id: Shout ID.
|
||||||
"""
|
"""
|
||||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
session.query(Shout).filter(Shout.id == shout_id).update({"featured_at": None})
|
||||||
Shout.update(s, {"featured_at": None})
|
|
||||||
session.add(s)
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
async def _create_reaction(session, info, shout, author_id: int, reaction) -> dict:
|
async def _create_reaction(session, info, shout, author_id: int, reaction) -> dict:
|
||||||
"""
|
"""
|
||||||
Создает новую реакцию и выполняет связанные с этим действия, такие как обновление счетчиков и уведомление.
|
Create a new reaction and perform related actions such as updating counters and notification.
|
||||||
|
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param shout: Объект публикации.
|
:param shout: Shout object.
|
||||||
:param author_id: Идентификатор автора.
|
:param author_id: Author ID.
|
||||||
:param reaction: Словарь с данными реакции.
|
:param reaction: Dictionary with reaction data.
|
||||||
:return: Словарь с данными о созданной реакции.
|
:return: Dictionary with created reaction data.
|
||||||
"""
|
"""
|
||||||
r = Reaction(**reaction)
|
r = Reaction(**reaction)
|
||||||
session.add(r)
|
session.add(r)
|
||||||
session.commit()
|
session.commit()
|
||||||
rdict = r.dict()
|
rdict = r.dict()
|
||||||
|
|
||||||
# Пересчет счетчика комментариев
|
# Update author stat for comments
|
||||||
if str(r.kind) == ReactionKind.COMMENT.value:
|
if r.kind == ReactionKind.COMMENT.value:
|
||||||
update_author_stat(author_id)
|
update_author_stat(author_id)
|
||||||
|
|
||||||
# Совместное редактирование
|
# Handle proposal
|
||||||
if rdict.get("reply_to") and r.kind in PROPOSAL_REACTIONS and author_id in shout.authors:
|
if r.reply_to and r.kind in PROPOSAL_REACTIONS and author_id in shout.authors:
|
||||||
handle_proposing(session, r, shout)
|
handle_proposing(session, r, shout)
|
||||||
|
|
||||||
# Рейтинг и саморегуляция
|
# Handle rating
|
||||||
if r.kind in RATING_REACTIONS:
|
if r.kind in RATING_REACTIONS:
|
||||||
# Механизм саморегуляции
|
|
||||||
if check_to_unfeature(session, author_id, r):
|
if check_to_unfeature(session, author_id, r):
|
||||||
set_unfeatured(session, shout.id)
|
set_unfeatured(session, shout.id)
|
||||||
elif check_to_feature(session, author_id, r):
|
elif check_to_feature(session, author_id, r):
|
||||||
await set_featured(session, shout.id)
|
await set_featured(session, shout.id)
|
||||||
|
|
||||||
# Подписка, если понравилось
|
# Follow if liked
|
||||||
if r.kind == ReactionKind.LIKE.value:
|
if r.kind == ReactionKind.LIKE.value:
|
||||||
try:
|
try:
|
||||||
# Автоподписка при реакции
|
|
||||||
follow(None, info, "shout", shout.slug)
|
follow(None, info, "shout", shout.slug)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Обновление счетчика комментариев в кэше
|
# Notify creation
|
||||||
if str(r.kind) == ReactionKind.COMMENT.value:
|
|
||||||
update_author_stat(author_id)
|
|
||||||
|
|
||||||
rdict["shout"] = shout.dict()
|
|
||||||
rdict["stat"] = {"commented": 0, "reacted": 0, "rating": 0}
|
|
||||||
|
|
||||||
# Уведомление о создании
|
|
||||||
await notify_reaction(rdict, "create")
|
await notify_reaction(rdict, "create")
|
||||||
|
|
||||||
return rdict
|
return rdict
|
||||||
|
@ -198,47 +231,36 @@ async def _create_reaction(session, info, shout, author_id: int, reaction) -> di
|
||||||
|
|
||||||
def prepare_new_rating(reaction: dict, shout_id: int, session, author_id: int):
|
def prepare_new_rating(reaction: dict, shout_id: int, session, author_id: int):
|
||||||
"""
|
"""
|
||||||
Проверяет возможность выставления новой оценки для публикации.
|
Check for the possibility of rating a shout.
|
||||||
|
|
||||||
:param reaction: Словарь с данными реакции.
|
:param reaction: Dictionary with reaction data.
|
||||||
:param shout_id: Идентификатор публикации.
|
:param shout_id: Shout ID.
|
||||||
:param session: Сессия базы данных.
|
:param session: Database session.
|
||||||
:param author_id: Идентификатор автора.
|
:param author_id: Author ID.
|
||||||
:return: Словарь с ошибкой или None.
|
:return: Dictionary with error or None.
|
||||||
"""
|
"""
|
||||||
kind = reaction.get("kind")
|
kind = reaction.get("kind")
|
||||||
opposite_kind = ReactionKind.DISLIKE.value if is_positive(kind) else ReactionKind.LIKE.value
|
opposite_kind = ReactionKind.DISLIKE.value if is_positive(kind) else ReactionKind.LIKE.value
|
||||||
|
|
||||||
# Формирование запроса для проверки существующих оценок
|
existing_ratings = (
|
||||||
q = select(Reaction).filter(
|
session.query(Reaction)
|
||||||
and_(
|
.filter(
|
||||||
Reaction.shout == shout_id,
|
Reaction.shout == shout_id,
|
||||||
Reaction.created_by == author_id,
|
Reaction.created_by == author_id,
|
||||||
Reaction.kind.in_(RATING_REACTIONS),
|
Reaction.kind.in_(RATING_REACTIONS),
|
||||||
Reaction.deleted_at.is_not(None),
|
Reaction.deleted_at.is_(None),
|
||||||
)
|
)
|
||||||
|
.all()
|
||||||
)
|
)
|
||||||
reply_to = reaction.get("reply_to")
|
|
||||||
if reply_to and isinstance(reply_to, int):
|
|
||||||
q = q.filter(Reaction.reply_to == reply_to)
|
|
||||||
rating_reactions = session.execute(q).all()
|
|
||||||
|
|
||||||
# Проверка условий для выставления новой оценки
|
for r in existing_ratings:
|
||||||
if rating_reactions:
|
if r.kind == kind:
|
||||||
same_rating = filter(
|
|
||||||
lambda r: r.created_by == author_id and r.kind == kind,
|
|
||||||
rating_reactions,
|
|
||||||
)
|
|
||||||
opposite_rating = filter(
|
|
||||||
lambda r: r.created_by == author_id and r.kind == opposite_kind,
|
|
||||||
rating_reactions,
|
|
||||||
)
|
|
||||||
if same_rating:
|
|
||||||
return {"error": "You can't rate the same thing twice"}
|
return {"error": "You can't rate the same thing twice"}
|
||||||
elif opposite_rating:
|
if r.kind == opposite_kind:
|
||||||
return {"error": "Remove opposite vote first"}
|
return {"error": "Remove opposite vote first"}
|
||||||
elif filter(lambda r: r.created_by == author_id, rating_reactions):
|
if shout_id in [r.shout for r in existing_ratings]:
|
||||||
return {"error": "You can't rate your own thing"}
|
return {"error": "You can't rate your own thing"}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,34 +268,27 @@ def prepare_new_rating(reaction: dict, shout_id: int, session, author_id: int):
|
||||||
@login_required
|
@login_required
|
||||||
async def create_reaction(_, info, reaction):
|
async def create_reaction(_, info, reaction):
|
||||||
"""
|
"""
|
||||||
Создает новую реакцию через GraphQL запрос.
|
Create a new reaction through a GraphQL request.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param reaction: Словарь с данными реакции.
|
:param reaction: Dictionary with reaction data.
|
||||||
:return: Словарь с информацией о созданной реакции или ошибкой.
|
:return: Dictionary with created reaction data or error.
|
||||||
"""
|
"""
|
||||||
# logger.debug(f"{info.context} for {reaction}")
|
|
||||||
info.context.get("user_id")
|
|
||||||
author_dict = info.context.get("author", {})
|
author_dict = info.context.get("author", {})
|
||||||
if not isinstance(author_dict, dict):
|
|
||||||
return {"error": "Unauthorized"}
|
|
||||||
author_id = author_dict.get("id")
|
author_id = author_dict.get("id")
|
||||||
shout_id = reaction.get("shout")
|
shout_id = reaction.get("shout")
|
||||||
if not shout_id:
|
|
||||||
return {"error": "Shout ID is required to create a reaction."}
|
if not shout_id or not author_id:
|
||||||
|
return {"error": "Shout ID and author ID are required to create a reaction."}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
if shout and author_id:
|
if shout:
|
||||||
reaction["created_by"] = int(author_id)
|
reaction["created_by"] = author_id
|
||||||
kind = reaction.get("kind")
|
kind = reaction.get(
|
||||||
|
"kind", ReactionKind.COMMENT.value if isinstance(reaction.get("body"), str) else None
|
||||||
if not kind and isinstance(reaction.get("body"), str):
|
)
|
||||||
kind = ReactionKind.COMMENT.value
|
|
||||||
|
|
||||||
if not kind:
|
|
||||||
return {"error": "cannot create reaction without a kind"}
|
|
||||||
|
|
||||||
if kind in RATING_REACTIONS:
|
if kind in RATING_REACTIONS:
|
||||||
error_result = prepare_new_rating(reaction, shout_id, session, author_id)
|
error_result = prepare_new_rating(reaction, shout_id, session, author_id)
|
||||||
|
@ -282,15 +297,11 @@ async def create_reaction(_, info, reaction):
|
||||||
|
|
||||||
rdict = await _create_reaction(session, info, shout, author_id, reaction)
|
rdict = await _create_reaction(session, info, shout, author_id, reaction)
|
||||||
|
|
||||||
# TODO: call recount ratings periodically
|
# Return created reaction
|
||||||
rdict["created_by"] = author_dict
|
rdict["created_by"] = author_dict
|
||||||
return {"reaction": rdict}
|
return {"reaction": rdict}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
|
||||||
|
|
||||||
traceback.print_exc()
|
|
||||||
logger.error(f"{type(e).__name__}: {e}")
|
logger.error(f"{type(e).__name__}: {e}")
|
||||||
|
|
||||||
return {"error": "Cannot create reaction."}
|
return {"error": "Cannot create reaction."}
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,45 +309,40 @@ async def create_reaction(_, info, reaction):
|
||||||
@login_required
|
@login_required
|
||||||
async def update_reaction(_, info, reaction):
|
async def update_reaction(_, info, reaction):
|
||||||
"""
|
"""
|
||||||
Обновляет существующую реакцию через GraphQL запрос.
|
Update an existing reaction through a GraphQL request.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param reaction: Словарь с данными реакции.
|
:param reaction: Dictionary with reaction data.
|
||||||
:return: Словарь с информацией об обновленной реакции или ошибкой.
|
:return: Dictionary with updated reaction data or error.
|
||||||
"""
|
"""
|
||||||
logger.debug(f"{info.context} for {reaction}")
|
|
||||||
user_id = info.context.get("user_id")
|
user_id = info.context.get("user_id")
|
||||||
roles = info.context.get("roles")
|
roles = info.context.get("roles")
|
||||||
rid = reaction.get("id")
|
rid = reaction.get("id")
|
||||||
if rid and isinstance(rid, int) and user_id and roles:
|
|
||||||
|
if not rid or not user_id or not roles:
|
||||||
|
return {"error": "Invalid input data"}
|
||||||
|
|
||||||
del reaction["id"]
|
del reaction["id"]
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
reaction_query = select(Reaction).filter(Reaction.id == rid)
|
try:
|
||||||
aliased_reaction = aliased(Reaction)
|
reaction_query = query_reactions().filter(Reaction.id == rid)
|
||||||
reaction_query = add_reaction_stat_columns(reaction_query, aliased_reaction)
|
reaction_query = add_reaction_stat_columns(reaction_query)
|
||||||
reaction_query = reaction_query.group_by(Reaction.id)
|
reaction_query = reaction_query.group_by(Reaction.id)
|
||||||
|
|
||||||
try:
|
|
||||||
result = session.execute(reaction_query).unique().first()
|
result = session.execute(reaction_query).unique().first()
|
||||||
if result:
|
if result:
|
||||||
[r, commented_stat, rating_stat] = result
|
r, commented_stat, rating_stat = result
|
||||||
if not r:
|
|
||||||
return {"error": "invalid reaction id"}
|
|
||||||
|
|
||||||
author = session.query(Author).filter(Author.user == user_id).first()
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
if author:
|
if not r or not author:
|
||||||
|
return {"error": "Invalid reaction ID or unauthorized"}
|
||||||
|
|
||||||
if r.created_by != author.id and "editor" not in roles:
|
if r.created_by != author.id and "editor" not in roles:
|
||||||
return {"error": "access denied"}
|
return {"error": "Access denied"}
|
||||||
|
|
||||||
body = reaction.get("body")
|
# Update reaction
|
||||||
if body:
|
r.body = reaction.get("body", r.body)
|
||||||
r.body = body
|
|
||||||
r.updated_at = int(time.time())
|
r.updated_at = int(time.time())
|
||||||
|
|
||||||
if r.kind != reaction["kind"]:
|
|
||||||
# Определение изменения мнения может быть реализовано здесь
|
|
||||||
pass
|
|
||||||
|
|
||||||
Reaction.update(r, reaction)
|
Reaction.update(r, reaction)
|
||||||
session.add(r)
|
session.add(r)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
@ -349,91 +355,92 @@ async def update_reaction(_, info, reaction):
|
||||||
await notify_reaction(r.dict(), "update")
|
await notify_reaction(r.dict(), "update")
|
||||||
|
|
||||||
return {"reaction": r}
|
return {"reaction": r}
|
||||||
else:
|
except Exception as e:
|
||||||
return {"error": "not authorized"}
|
logger.error(f"{type(e).__name__}: {e}")
|
||||||
except Exception:
|
return {"error": "Cannot update reaction"}
|
||||||
import traceback
|
|
||||||
|
|
||||||
traceback.print_exc()
|
|
||||||
return {"error": "cannot create reaction"}
|
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("delete_reaction")
|
@mutation.field("delete_reaction")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_reaction(_, info, reaction_id: int):
|
async def delete_reaction(_, info, reaction_id: int):
|
||||||
"""
|
"""
|
||||||
Удаляет существующую реакцию через GraphQL запрос.
|
Delete an existing reaction through a GraphQL request.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param reaction_id: Идентификатор удаляемой реакции.
|
:param reaction_id: Reaction ID to delete.
|
||||||
:return: Словарь с информацией об удаленной реакции или ошибкой.
|
:return: Dictionary with deleted reaction data or error.
|
||||||
"""
|
"""
|
||||||
logger.debug(f"{info.context} for {reaction_id}")
|
|
||||||
user_id = info.context.get("user_id")
|
user_id = info.context.get("user_id")
|
||||||
author_id = info.context.get("author", {}).get("id")
|
author_id = info.context.get("author", {}).get("id")
|
||||||
roles = info.context.get("roles", [])
|
roles = info.context.get("roles", [])
|
||||||
if user_id:
|
|
||||||
|
if not user_id:
|
||||||
|
return {"error": "Unauthorized"}
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
try:
|
try:
|
||||||
author = session.query(Author).filter(Author.user == user_id).one()
|
author = session.query(Author).filter(Author.user == user_id).one()
|
||||||
r = session.query(Reaction).filter(Reaction.id == reaction_id).one()
|
r = session.query(Reaction).filter(Reaction.id == reaction_id).one()
|
||||||
|
|
||||||
if r.created_by != author_id and "editor" not in roles:
|
if r.created_by != author_id and "editor" not in roles:
|
||||||
return {"error": "access denied"}
|
return {"error": "Access denied"}
|
||||||
|
|
||||||
logger.debug(f"{user_id} user removing his #{reaction_id} reaction")
|
logger.debug(f"{user_id} user removing his #{reaction_id} reaction")
|
||||||
reaction_dict = r.dict()
|
reaction_dict = r.dict()
|
||||||
session.delete(r)
|
session.delete(r)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# Обновление счетчика комментариев в кэше
|
# Update author stat
|
||||||
if str(r.kind) == ReactionKind.COMMENT.value:
|
if r.kind == ReactionKind.COMMENT.value:
|
||||||
update_author_stat(author.id)
|
update_author_stat(author.id)
|
||||||
|
|
||||||
await notify_reaction(reaction_dict, "delete")
|
await notify_reaction(reaction_dict, "delete")
|
||||||
|
|
||||||
return {"error": None, "reaction": reaction_dict}
|
return {"error": None, "reaction": reaction_dict}
|
||||||
except Exception as exc:
|
except Exception as e:
|
||||||
return {"error": f"cannot delete reaction: {exc}"}
|
logger.error(f"{type(e).__name__}: {e}")
|
||||||
return {"error": "cannot delete reaction"}
|
return {"error": "Cannot delete reaction"}
|
||||||
|
|
||||||
|
|
||||||
def apply_reaction_filters(by, q):
|
def apply_reaction_filters(by, q):
|
||||||
"""
|
"""
|
||||||
Применяет фильтры к запросу реакций.
|
Apply filters to a reaction query.
|
||||||
|
|
||||||
:param by: Словарь с параметрами фильтрации.
|
:param by: Dictionary with filter parameters.
|
||||||
:param q: SQL-запрос.
|
:param q: SQL query.
|
||||||
:return: Запрос с примененными фильтрами.
|
:return: Query with applied filters.
|
||||||
"""
|
"""
|
||||||
shout_slug = by.get("shout", None)
|
shout_slug = by.get("shout")
|
||||||
if shout_slug:
|
if shout_slug:
|
||||||
q = q.filter(Shout.slug == shout_slug)
|
q = q.filter(Shout.slug == shout_slug)
|
||||||
|
|
||||||
elif by.get("shouts"):
|
shouts = by.get("shouts")
|
||||||
q = q.filter(Shout.slug.in_(by.get("shouts", [])))
|
if shouts:
|
||||||
|
q = q.filter(Shout.slug.in_(shouts))
|
||||||
|
|
||||||
created_by = by.get("created_by", None)
|
created_by = by.get("created_by")
|
||||||
if created_by:
|
if created_by:
|
||||||
q = q.filter(Author.id == created_by)
|
q = q.filter(Author.id == created_by)
|
||||||
|
|
||||||
author_slug = by.get("author", None)
|
author_slug = by.get("author")
|
||||||
if author_slug:
|
if author_slug:
|
||||||
q = q.filter(Author.slug == author_slug)
|
q = q.filter(Author.slug == author_slug)
|
||||||
|
|
||||||
topic = by.get("topic", None)
|
topic = by.get("topic")
|
||||||
if isinstance(topic, int):
|
if isinstance(topic, int):
|
||||||
q = q.filter(Shout.topics.any(id=topic))
|
q = q.filter(Shout.topics.any(id=topic))
|
||||||
|
|
||||||
if by.get("comment", False):
|
if by.get("comment"):
|
||||||
q = q.filter(Reaction.kind == ReactionKind.COMMENT.value)
|
q = q.filter(Reaction.kind == ReactionKind.COMMENT.value)
|
||||||
|
|
||||||
if by.get("rating", False):
|
if by.get("rating"):
|
||||||
q = q.filter(Reaction.kind.in_(RATING_REACTIONS))
|
q = q.filter(Reaction.kind.in_(RATING_REACTIONS))
|
||||||
|
|
||||||
by_search = by.get("search", "")
|
by_search = by.get("search", "")
|
||||||
if len(by_search) > 2:
|
if len(by_search) > 2:
|
||||||
q = q.filter(Reaction.body.ilike(f"%{by_search}%"))
|
q = q.filter(Reaction.body.ilike(f"%{by_search}%"))
|
||||||
|
|
||||||
after = by.get("after", None)
|
after = by.get("after")
|
||||||
if isinstance(after, int):
|
if isinstance(after, int):
|
||||||
q = q.filter(Reaction.created_at > after)
|
q = q.filter(Reaction.created_at > after)
|
||||||
|
|
||||||
|
@ -443,45 +450,24 @@ def apply_reaction_filters(by, q):
|
||||||
@query.field("load_reactions_by")
|
@query.field("load_reactions_by")
|
||||||
async def load_reactions_by(_, info, by, limit=50, offset=0):
|
async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||||
"""
|
"""
|
||||||
Загружает реакции по указанным параметрам.
|
Load reactions based on specified parameters.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param by: {
|
:param by: Filter parameters.
|
||||||
:shout - фильтрация по slug публикации
|
:param limit: Number of reactions to load.
|
||||||
:shouts - фильтрация по списку slug публикаций
|
:param offset: Pagination offset.
|
||||||
:created_by - фильтрация по идентификатору автора
|
:return: List of reactions.
|
||||||
:author - фильтрация по slug автора
|
|
||||||
:topic - фильтрация по теме
|
|
||||||
:search - поиск по тексту реакций
|
|
||||||
:comment - фильтрация комментариев
|
|
||||||
:rating - фильтрация реакций с рейтингом
|
|
||||||
:after - фильтрация по времени создания
|
|
||||||
:sort - поле для сортировки (по убыванию по умолчанию)
|
|
||||||
}
|
|
||||||
:param limit: Количество реакций для загрузки.
|
|
||||||
:param offset: Смещение для пагинации.
|
|
||||||
:return: Список реакций.
|
|
||||||
"""
|
"""
|
||||||
q = (
|
q = query_reactions()
|
||||||
select(Reaction, Author, Shout)
|
|
||||||
.select_from(Reaction)
|
|
||||||
.join(Author, Reaction.created_by == Author.id)
|
|
||||||
.join(Shout, Reaction.shout == Shout.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Подсчет статистики
|
# Add statistics and apply filters
|
||||||
aliased_reaction = aliased(Reaction)
|
q = add_reaction_stat_columns(q)
|
||||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
|
||||||
|
|
||||||
# Применение фильтров
|
|
||||||
q = apply_reaction_filters(by, q)
|
q = apply_reaction_filters(by, q)
|
||||||
q = q.where(Reaction.deleted_at.is_(None))
|
q = q.where(Reaction.deleted_at.is_(None))
|
||||||
|
|
||||||
# Группировка
|
# Group and sort
|
||||||
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.id)
|
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
||||||
|
order_stat = by.get("sort", "").lower()
|
||||||
# Сортировка
|
|
||||||
order_stat = by.get("sort", "").lower() # 'like' | 'dislike' | 'newest' | 'oldest'
|
|
||||||
order_by_stmt = desc(Reaction.created_at)
|
order_by_stmt = desc(Reaction.created_at)
|
||||||
if order_stat == "oldest":
|
if order_stat == "oldest":
|
||||||
order_by_stmt = asc(Reaction.created_at)
|
order_by_stmt = asc(Reaction.created_at)
|
||||||
|
@ -489,159 +475,93 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||||
order_by_stmt = desc("rating_stat")
|
order_by_stmt = desc("rating_stat")
|
||||||
q = q.order_by(order_by_stmt)
|
q = q.order_by(order_by_stmt)
|
||||||
|
|
||||||
# Пагинация
|
# Retrieve and return reactions
|
||||||
q = q.limit(limit).offset(offset)
|
return get_reactions_with_stat(q, limit, offset)
|
||||||
|
|
||||||
reactions = set()
|
|
||||||
with local_session() as session:
|
|
||||||
result_rows = session.execute(q)
|
|
||||||
for [reaction, author, shout, commented_stat, rating_stat] in result_rows:
|
|
||||||
reaction.created_by = author
|
|
||||||
reaction.shout = shout
|
|
||||||
reaction.stat = {"rating": rating_stat, "commented": commented_stat}
|
|
||||||
reactions.add(reaction)
|
|
||||||
|
|
||||||
return reactions
|
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shout_ratings")
|
@query.field("load_shout_ratings")
|
||||||
async def load_shout_ratings(_, info, shout: int, limit=100, offset=0):
|
async def load_shout_ratings(_, info, shout: int, limit=100, offset=0):
|
||||||
"""
|
"""
|
||||||
Получает оценки для указанной публикации с пагинацией.
|
Load ratings for a specified shout with pagination.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param shout: Идентификатор публикации.
|
:param shout: Shout ID.
|
||||||
:param limit: Количество реакций для загрузки.
|
:param limit: Number of reactions to load.
|
||||||
:param offset: Смещение для пагинации.
|
:param offset: Pagination offset.
|
||||||
:return: Список реакций.
|
:return: List of reactions.
|
||||||
"""
|
"""
|
||||||
q = (
|
q = query_reactions()
|
||||||
select(Reaction, Author, Shout)
|
|
||||||
.select_from(Reaction)
|
# Filter, group, sort, limit, offset
|
||||||
.join(Author, Reaction.created_by == Author.id)
|
q = q.filter(
|
||||||
.join(Shout, Reaction.shout == Shout.id)
|
and_(
|
||||||
|
Reaction.deleted_at.is_(None),
|
||||||
|
Reaction.shout == shout,
|
||||||
|
Reaction.kind.in_(RATING_REACTIONS),
|
||||||
)
|
)
|
||||||
|
)
|
||||||
# Фильтрация, группировка, сортировка, лимит, офсет
|
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
||||||
q = q.filter(and_(Reaction.deleted_at.is_(None), Reaction.shout == shout, Reaction.kind.in_(RATING_REACTIONS)))
|
|
||||||
q = q.group_by(Reaction.id)
|
|
||||||
q = q.order_by(desc(Reaction.created_at))
|
q = q.order_by(desc(Reaction.created_at))
|
||||||
q = q.limit(limit).offset(offset)
|
|
||||||
|
|
||||||
reactions = set()
|
# Retrieve and return reactions
|
||||||
with local_session() as session:
|
return get_reactions_with_stat(q, limit, offset)
|
||||||
result_rows = session.execute(q)
|
|
||||||
for [
|
|
||||||
reaction,
|
|
||||||
author,
|
|
||||||
shout,
|
|
||||||
] in result_rows:
|
|
||||||
reaction.created_by = author
|
|
||||||
reaction.shout = shout
|
|
||||||
reactions.add(reaction)
|
|
||||||
|
|
||||||
return reactions
|
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shout_comments")
|
@query.field("load_shout_comments")
|
||||||
async def load_shout_comments(_, info, shout: int, limit=50, offset=0):
|
async def load_shout_comments(_, info, shout: int, limit=50, offset=0):
|
||||||
"""
|
"""
|
||||||
Получает комментарии для указанной публикации с пагинацией и статистикой.
|
Load comments for a specified shout with pagination and statistics.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param shout: Идентификатор публикации.
|
:param shout: Shout ID.
|
||||||
:param limit: Количество комментариев для загрузки.
|
:param limit: Number of comments to load.
|
||||||
:param offset: Смещение для пагинации.
|
:param offset: Pagination offset.
|
||||||
:return: Список реакций.
|
:return: List of reactions.
|
||||||
"""
|
"""
|
||||||
aliased_reaction = aliased(Reaction)
|
q = query_reactions()
|
||||||
q = (
|
|
||||||
select(
|
|
||||||
Reaction,
|
|
||||||
Author,
|
|
||||||
Shout,
|
|
||||||
func.count(aliased_reaction.id).label("reacted_stat"),
|
|
||||||
func.count(aliased_reaction.body).label("commented_stat"),
|
|
||||||
func.sum(case((aliased_reaction.kind == str(ReactionKind.LIKE.value), 1), else_=0)).label("likes_stat"),
|
|
||||||
func.sum(case((aliased_reaction.kind == str(ReactionKind.DISLIKE.value), 1), else_=0)).label(
|
|
||||||
"dislikes_stat"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.select_from(Reaction)
|
|
||||||
.join(Author, Reaction.created_by == Author.id)
|
|
||||||
.join(Shout, Reaction.shout == Shout.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Фильтрация, группировка, сортировка, лимит, офсет
|
q = add_reaction_stat_columns(q)
|
||||||
q = q.filter(and_(Reaction.deleted_at.is_(None), Reaction.shout == shout, Reaction.body.is_not(None)))
|
|
||||||
|
# Filter, group, sort, limit, offset
|
||||||
|
q = q.filter(
|
||||||
|
and_(
|
||||||
|
Reaction.deleted_at.is_(None),
|
||||||
|
Reaction.shout == shout,
|
||||||
|
Reaction.body.is_not(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
||||||
q = q.order_by(desc(Reaction.created_at))
|
q = q.order_by(desc(Reaction.created_at))
|
||||||
q = q.limit(limit).offset(offset)
|
|
||||||
|
|
||||||
reactions = set()
|
# Retrieve and return reactions
|
||||||
with local_session() as session:
|
return get_reactions_with_stat(q, limit, offset)
|
||||||
result_rows = session.execute(q)
|
|
||||||
for row in result_rows:
|
|
||||||
reaction, author, shout, reacted_stat, commented_stat, likes_stat, dislikes_stat = row
|
|
||||||
reaction.created_by = author
|
|
||||||
reaction.shout = shout
|
|
||||||
reaction.stat = {
|
|
||||||
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
|
||||||
"reacted": reacted_stat,
|
|
||||||
"commented": commented_stat,
|
|
||||||
}
|
|
||||||
reactions.add(reaction)
|
|
||||||
|
|
||||||
return list(reactions)
|
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_comment_ratings")
|
@query.field("load_comment_ratings")
|
||||||
async def load_comment_ratings(_, info, comment: int, limit=50, offset=0):
|
async def load_comment_ratings(_, info, comment: int, limit=50, offset=0):
|
||||||
"""
|
"""
|
||||||
Получает оценки для указанного комментария с пагинацией и статистикой.
|
Load ratings for a specified comment with pagination and statistics.
|
||||||
|
|
||||||
:param info: Информация о контексте GraphQL.
|
:param info: GraphQL context info.
|
||||||
:param comment: Идентификатор комментария.
|
:param comment: Comment ID.
|
||||||
:param limit: Количество оценок для загрузки.
|
:param limit: Number of ratings to load.
|
||||||
:param offset: Смещение для пагинации.
|
:param offset: Pagination offset.
|
||||||
:return: Список реакций.
|
:return: List of reactions.
|
||||||
"""
|
"""
|
||||||
aliased_reaction = aliased(Reaction)
|
q = query_reactions()
|
||||||
q = (
|
|
||||||
select(
|
|
||||||
Reaction,
|
|
||||||
Author,
|
|
||||||
Shout,
|
|
||||||
func.count(aliased_reaction.id).label("reacted_stat"),
|
|
||||||
func.count(aliased_reaction.body).label("commented_stat"),
|
|
||||||
func.sum(case((aliased_reaction.kind == str(ReactionKind.LIKE.value), 1), else_=0)).label("likes_stat"),
|
|
||||||
func.sum(case((aliased_reaction.kind == str(ReactionKind.DISLIKE.value), 1), else_=0)).label(
|
|
||||||
"dislikes_stat"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.select_from(Reaction)
|
|
||||||
.join(Author, Reaction.created_by == Author.id)
|
|
||||||
.join(Shout, Reaction.shout == Shout.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Фильтрация, группировка, сортировка, лимит, офсет
|
q = add_reaction_stat_columns(q)
|
||||||
q = q.filter(and_(Reaction.deleted_at.is_(None), Reaction.reply_to == comment, Reaction.body.is_not(None)))
|
|
||||||
|
# Filter, group, sort, limit, offset
|
||||||
|
q = q.filter(
|
||||||
|
and_(
|
||||||
|
Reaction.deleted_at.is_(None),
|
||||||
|
Reaction.reply_to == comment,
|
||||||
|
Reaction.kind == ReactionKind.COMMENT.value,
|
||||||
|
)
|
||||||
|
)
|
||||||
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
q = q.group_by(Reaction.id, Author.id, Shout.id)
|
||||||
q = q.order_by(desc(Reaction.created_at))
|
q = q.order_by(desc(Reaction.created_at))
|
||||||
q = q.limit(limit).offset(offset)
|
|
||||||
|
|
||||||
reactions = set()
|
# Retrieve and return reactions
|
||||||
with local_session() as session:
|
return get_reactions_with_stat(q, limit, offset)
|
||||||
result_rows = session.execute(q)
|
|
||||||
for row in result_rows:
|
|
||||||
reaction, author, shout, reacted_stat, commented_stat, likes_stat, dislikes_stat = row
|
|
||||||
reaction.created_by = author
|
|
||||||
reaction.shout = shout
|
|
||||||
reaction.stat = {
|
|
||||||
"rating": int(likes_stat or 0) - int(dislikes_stat or 0),
|
|
||||||
"reacted": reacted_stat,
|
|
||||||
"commented": commented_stat,
|
|
||||||
}
|
|
||||||
reactions.add(reaction)
|
|
||||||
|
|
||||||
return list(reactions)
|
|
||||||
|
|
|
@ -83,8 +83,10 @@ def query_shouts(slug=None):
|
||||||
q = (
|
q = (
|
||||||
select(
|
select(
|
||||||
Shout,
|
Shout,
|
||||||
func.count().filter(aliased_reaction.kind == ReactionKind.COMMENT.value).label("comments_stat"),
|
func.count(aliased_reaction.id)
|
||||||
func.count(distinct(ShoutReactionsFollower.follower)).label("followers_stat"),
|
.filter(aliased_reaction.kind == ReactionKind.COMMENT.value)
|
||||||
|
.label("comments_stat"),
|
||||||
|
func.count(ShoutReactionsFollower.follower).label("followers_stat"),
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
|
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
|
||||||
|
@ -97,7 +99,7 @@ def query_shouts(slug=None):
|
||||||
topics_subquery.c.topics.label("topics"),
|
topics_subquery.c.topics.label("topics"),
|
||||||
topics_subquery.c.main_topic_slug.label("main_topic_slug"),
|
topics_subquery.c.main_topic_slug.label("main_topic_slug"),
|
||||||
)
|
)
|
||||||
.outerjoin(aliased_reaction, aliased_reaction.shout == Shout.id)
|
.outerjoin(aliased_reaction, and_(aliased_reaction.shout == Shout.id, aliased_reaction.deleted_at.is_(None)))
|
||||||
.outerjoin(authors_subquery, authors_subquery.c.shout_id == Shout.id)
|
.outerjoin(authors_subquery, authors_subquery.c.shout_id == Shout.id)
|
||||||
.outerjoin(topics_subquery, topics_subquery.c.shout_id == Shout.id)
|
.outerjoin(topics_subquery, topics_subquery.c.shout_id == Shout.id)
|
||||||
.outerjoin(ShoutReactionsFollower, ShoutReactionsFollower.shout == Shout.id)
|
.outerjoin(ShoutReactionsFollower, ShoutReactionsFollower.shout == Shout.id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user