commented->comments_count
All checks were successful
Deploy on push / deploy (push) Successful in 55s
All checks were successful
Deploy on push / deploy (push) Successful in 55s
This commit is contained in:
parent
3c56fdfaea
commit
a5eaf4bb65
|
@ -3,7 +3,7 @@
|
|||
- Created new GraphQL query `load_comments_branch` for efficient loading of hierarchical comments
|
||||
- Ability to load root comments with their first N replies
|
||||
- Added pagination for both root and child comments
|
||||
- Using existing `commented` field in `Stat` type to display number of replies
|
||||
- Using existing `comments_count` field in `Stat` type to display number of replies
|
||||
- Added special `first_replies` field to store first replies to a comment
|
||||
- Optimized SQL queries for efficient loading of comment hierarchies
|
||||
- Implemented flexible comment sorting system (by time, rating)
|
||||
|
@ -150,7 +150,7 @@
|
|||
#### [0.4.4]
|
||||
- `followers_stat` removed for shout
|
||||
- sqlite3 support added
|
||||
- `rating_stat` and `commented_stat` fixes
|
||||
- `rating_stat` and `comments_count` fixes
|
||||
|
||||
#### [0.4.3]
|
||||
- cache reimplemented
|
||||
|
|
|
@ -45,7 +45,7 @@ query LoadCommentsBranch(
|
|||
reply_to
|
||||
stat {
|
||||
rating
|
||||
commented
|
||||
comments_count
|
||||
}
|
||||
first_replies {
|
||||
id
|
||||
|
@ -61,7 +61,7 @@ query LoadCommentsBranch(
|
|||
reply_to
|
||||
stat {
|
||||
rating
|
||||
commented
|
||||
comments_count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ query LoadCommentsBranch(
|
|||
- `reply_to`: ID родительского комментария (null для корневых)
|
||||
- `first_replies`: Первые N дочерних комментариев
|
||||
- `stat`: Статистика комментария, включающая:
|
||||
- `commented`: Количество ответов на комментарий
|
||||
- `comments_count`: Количество ответов на комментарий
|
||||
- `rating`: Рейтинг комментария
|
||||
|
||||
## Примеры использования
|
||||
|
@ -150,7 +150,7 @@ const { data } = await client.query({
|
|||
1. Для эффективной работы со сложными ветками обсуждений рекомендуется:
|
||||
|
||||
- Сначала загружать только корневые комментарии с первыми N ответами
|
||||
- При наличии дополнительных ответов (когда `stat.commented > first_replies.length`)
|
||||
- При наличии дополнительных ответов (когда `stat.comments_count > first_replies.length`)
|
||||
добавить кнопку "Показать все ответы"
|
||||
- При нажатии на кнопку загружать дополнительные ответы с помощью запроса с указанным `parentId`
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
- Отдельный запрос `load_comments_branch` для оптимизированной загрузки ветки комментариев
|
||||
- Возможность загрузки корневых комментариев статьи с первыми ответами на них
|
||||
- Гибкая пагинация как для корневых, так и для дочерних комментариев
|
||||
- Использование поля `stat.commented` для отображения количества ответов на комментарий
|
||||
- Использование поля `stat.comments_count` для отображения количества ответов на комментарий
|
||||
- Добавление специального поля `first_replies` для хранения первых ответов на комментарий
|
||||
- Поддержка различных методов сортировки (новые, старые, популярные)
|
||||
- Оптимизированные SQL запросы для минимизации нагрузки на базу данных
|
|
@ -81,7 +81,7 @@ def get_reactions_with_stat(q, limit, offset):
|
|||
|
||||
with local_session() as session:
|
||||
result_rows = session.execute(q)
|
||||
for reaction, author, shout, commented_stat, rating_stat in result_rows:
|
||||
for reaction, author, shout, comments_count, rating_stat in result_rows:
|
||||
# Пропускаем реакции с отсутствующими shout или author
|
||||
if not shout or not author:
|
||||
logger.error(f"Пропущена реакция из-за отсутствия shout или author: {reaction.dict()}")
|
||||
|
@ -89,7 +89,7 @@ def get_reactions_with_stat(q, limit, offset):
|
|||
|
||||
reaction.created_by = author.dict()
|
||||
reaction.shout = shout.dict()
|
||||
reaction.stat = {"rating": rating_stat, "comments": commented_stat}
|
||||
reaction.stat = {"rating": rating_stat, "comments_count": comments_count}
|
||||
reactions.append(reaction)
|
||||
|
||||
return reactions
|
||||
|
@ -393,7 +393,7 @@ async def update_reaction(_, info, reaction):
|
|||
|
||||
result = session.execute(reaction_query).unique().first()
|
||||
if result:
|
||||
r, author, _shout, commented_stat, rating_stat = result
|
||||
r, author, _shout, comments_count, rating_stat = result
|
||||
if not r or not author:
|
||||
return {"error": "Invalid reaction ID or unauthorized"}
|
||||
|
||||
|
@ -408,7 +408,7 @@ async def update_reaction(_, info, reaction):
|
|||
session.commit()
|
||||
|
||||
r.stat = {
|
||||
"commented": commented_stat,
|
||||
"comments_count": comments_count,
|
||||
"rating": rating_stat,
|
||||
}
|
||||
|
||||
|
@ -713,7 +713,7 @@ async def load_comments_branch(
|
|||
|
||||
async def load_replies_count(comments):
|
||||
"""
|
||||
Загружает количество ответов для списка комментариев и обновляет поле stat.commented.
|
||||
Загружает количество ответов для списка комментариев и обновляет поле stat.comments_count.
|
||||
|
||||
:param comments: Список комментариев, для которых нужно загрузить количество ответов.
|
||||
"""
|
||||
|
@ -748,7 +748,7 @@ async def load_replies_count(comments):
|
|||
comment["stat"] = {}
|
||||
|
||||
# Обновляем счетчик комментариев в stat
|
||||
comment["stat"]["commented"] = replies_count.get(comment["id"], 0)
|
||||
comment["stat"]["comments_count"] = replies_count.get(comment["id"], 0)
|
||||
|
||||
|
||||
async def load_first_replies(comments, limit, offset, sort="newest"):
|
||||
|
|
|
@ -225,7 +225,7 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
|||
elif isinstance(row.stat, dict):
|
||||
stat = row.stat
|
||||
viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0
|
||||
shout_dict["stat"] = {**stat, "viewed": viewed, "commented": stat.get("comments_count", 0)}
|
||||
shout_dict["stat"] = {**stat, "viewed": viewed}
|
||||
|
||||
# Обработка main_topic и topics
|
||||
topics = None
|
||||
|
|
|
@ -137,7 +137,7 @@ type Draft {
|
|||
|
||||
type Stat {
|
||||
rating: Int
|
||||
commented: Int
|
||||
comments_count: Int
|
||||
viewed: Int
|
||||
last_commented_at: Int
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user