From 4d76c5ded005643a8c7bedd8800512ae7259eff9 Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Fri, 25 Jul 2025 11:07:39 +0500 Subject: [PATCH] refactor: updated bulk delete api task (#37068) --- lms/djangoapps/discussion/rest_api/tasks.py | 5 ++++- .../django_comment_common/comment_client/comment.py | 4 +++- .../django_comment_common/comment_client/thread.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/tasks.py b/lms/djangoapps/discussion/rest_api/tasks.py index da2a4a7c6e..d96fc8df09 100644 --- a/lms/djangoapps/discussion/rest_api/tasks.py +++ b/lms/djangoapps/discussion/rest_api/tasks.py @@ -10,6 +10,7 @@ from opaque_keys.edx.locator import CourseKey from eventtracking import tracker from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole +from common.djangoapps.track import segment from lms.djangoapps.courseware.courses import get_course_with_access from lms.djangoapps.discussion.django_comment_client.utils import get_user_role_names from lms.djangoapps.discussion.rest_api.discussions_notifications import DiscussionNotificationSender @@ -107,4 +108,6 @@ def delete_course_post_for_user(user_id, username, course_ids, event_data=None): "number_of_posts_deleted": threads_deleted, "number_of_comments_deleted": comments_deleted, }) - tracker.emit('edx.discussion.bulk_delete_user_posts', event_data) + event_name = 'edx.discussion.bulk_delete_user_posts' + tracker.emit(event_name, event_data) + segment.track('None', event_name, event_data) 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 3fb5e9d2d3..a368d09830 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py @@ -134,8 +134,10 @@ class Comment(models.Model): for comment in comments: start_time = time.time() comment_id = comment.get("_id") + course_id = comment.get("course_id") if comment_id: - comments_deleted += ForumComment().delete(comment_id) + forum_api.delete_comment(comment_id, course_id=course_id) + comments_deleted += 1 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 fc2459019e..af2424a5a0 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -262,8 +262,10 @@ class Thread(models.Model): for thread in threads: start_time = time.time() thread_id = thread.get("_id") + course_id = thread.get("course_id") if thread_id: - threads_deleted += CommentThread().delete(thread_id) + forum_api.delete_thread(thread_id, course_id=course_id) + threads_deleted += 1 log.info(f"<> Deleted thread {thread_id} in {time.time() - start_time} seconds." f" Thread Found: {thread_id is not None}") return threads_deleted