temp: added logs when bulk deleting comments and threads (#37063)

This commit is contained in:
Muhammad Adeel Tajamul
2025-07-25 04:46:18 +05:00
committed by GitHub
parent 47d253a1fe
commit 19cc088399
2 changed files with 17 additions and 0 deletions

View File

@@ -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"<<Bulk Delete>> 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"<<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

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