From 19cc0883990e1bfb1c2d53ba593880a98e255bed Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Fri, 25 Jul 2025 04:46:18 +0500 Subject: [PATCH] temp: added logs when bulk deleting comments and threads (#37063) --- .../django_comment_common/comment_client/comment.py | 11 +++++++++++ .../django_comment_common/comment_client/thread.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py index bfffa1c122..3fb5e9d2d3 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py @@ -1,4 +1,7 @@ # pylint: disable=missing-docstring,protected-access +import logging +import time + from bs4 import BeautifulSoup from openedx.core.djangoapps.django_comment_common.comment_client import models, settings @@ -9,6 +12,9 @@ from forum import api as forum_api from forum.backends.mongodb.comments import Comment as ForumComment +log = logging.getLogger(__name__) + + class Comment(models.Model): accessible_fields = [ @@ -117,16 +123,21 @@ class Comment(models.Model): Deletes comments and responses of user in the given course_ids. TODO: Add support for MySQL backend as well """ + start_time = time.time() query_params = { "course_id": {"$in": course_ids}, "author_id": str(user_id), } comments_deleted = 0 comments = ForumComment().get_list(**query_params) + log.info(f"<> Fetched comments for user {user_id} in {time.time() - start_time} seconds") for comment in comments: + start_time = time.time() comment_id = comment.get("_id") if comment_id: comments_deleted += ForumComment().delete(comment_id) + log.info(f"<> Deleted comment {comment_id} in {time.time() - start_time} seconds." + f" Comment Found: {comment_id is not None}") return comments_deleted diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py index 7c8986cbf3..fc2459019e 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -2,6 +2,7 @@ import logging +import time import typing as t from eventtracking import tracker @@ -250,16 +251,21 @@ class Thread(models.Model): Deletes threads of user in the given course_ids. TODO: Add support for MySQL backend as well """ + start_time = time.time() query_params = { "course_id": {"$in": course_ids}, "author_id": str(user_id), } threads_deleted = 0 threads = CommentThread().get_list(**query_params) + log.info(f"<> Fetched threads for user {user_id} in {time.time() - start_time} seconds") for thread in threads: + start_time = time.time() thread_id = thread.get("_id") if thread_id: threads_deleted += CommentThread().delete(thread_id) + log.info(f"<> Deleted thread {thread_id} in {time.time() - start_time} seconds." + f" Thread Found: {thread_id is not None}") return threads_deleted