From a5eaf4bb6510fad954a65feefbdb0aa218300662 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 26 Mar 2025 08:25:18 +0300 Subject: [PATCH] commented->comments_count --- CHANGELOG.md | 4 ++-- docs/comments-pagination.md | 8 ++++---- docs/features.md | 2 +- resolvers/reaction.py | 12 ++++++------ resolvers/reader.py | 2 +- schema/type.graphql | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4554ff14..80c7577e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/comments-pagination.md b/docs/comments-pagination.md index 3b34a0de..0f8f7261 100644 --- a/docs/comments-pagination.md +++ b/docs/comments-pagination.md @@ -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` diff --git a/docs/features.md b/docs/features.md index 37ff05fc..4837f870 100644 --- a/docs/features.md +++ b/docs/features.md @@ -42,7 +42,7 @@ - Отдельный запрос `load_comments_branch` для оптимизированной загрузки ветки комментариев - Возможность загрузки корневых комментариев статьи с первыми ответами на них - Гибкая пагинация как для корневых, так и для дочерних комментариев -- Использование поля `stat.commented` для отображения количества ответов на комментарий +- Использование поля `stat.comments_count` для отображения количества ответов на комментарий - Добавление специального поля `first_replies` для хранения первых ответов на комментарий - Поддержка различных методов сортировки (новые, старые, популярные) - Оптимизированные SQL запросы для минимизации нагрузки на базу данных \ No newline at end of file diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 35d2d536..24d5f941 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -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"): diff --git a/resolvers/reader.py b/resolvers/reader.py index 003a50cd..a8d6b026 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -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 diff --git a/schema/type.graphql b/schema/type.graphql index ee327e16..21243b81 100644 --- a/schema/type.graphql +++ b/schema/type.graphql @@ -137,7 +137,7 @@ type Draft { type Stat { rating: Int - commented: Int + comments_count: Int viewed: Int last_commented_at: Int }