refactor: updated bulk delete api task (#37068)

This commit is contained in:
Muhammad Adeel Tajamul
2025-07-25 11:07:39 +05:00
committed by GitHub
parent 9f454f6010
commit 4d76c5ded0
3 changed files with 10 additions and 3 deletions

View File

@@ -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)

View File

@@ -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"<<Bulk Delete>> Deleted comment {comment_id} in {time.time() - start_time} seconds."
f" Comment Found: {comment_id is not None}")
return comments_deleted

View File

@@ -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"<<Bulk Delete>> Deleted thread {thread_id} in {time.time() - start_time} seconds."
f" Thread Found: {thread_id is not None}")
return threads_deleted