temp: added logs for debugging in thread delete (#37127)

This commit is contained in:
Muhammad Adeel Tajamul
2025-08-06 12:06:58 +05:00
committed by GitHub
parent dc23ed7a31
commit 4cba98c513

View File

@@ -7,10 +7,16 @@ import typing as t
from eventtracking import tracker
from . import models, settings, utils
from django.core.exceptions import ObjectDoesNotExist
from forum import api as forum_api
from openedx.core.djangoapps.discussions.config.waffle import is_forum_v2_enabled, is_forum_v2_disabled_globally
from forum.api.threads import prepare_thread_api_response
from forum.backend import get_backend
from forum.backends.mongodb.threads import CommentThread
from forum.utils import ForumV2RequestError
from rest_framework.serializers import ValidationError
from openedx.core.djangoapps.discussions.config.waffle import is_forum_v2_enabled, is_forum_v2_disabled_globally
from . import models, settings, utils
log = logging.getLogger(__name__)
@@ -245,6 +251,50 @@ class Thread(models.Model):
}
return CommentThread()._collection.count_documents(query_params) # pylint: disable=protected-access
@classmethod
def _delete_thread(cls, thread_id, course_id=None):
"""
Deletes a thread
"""
prefix = "<<Bulk Delete Thread>>"
backend = get_backend(course_id)()
try:
start_time = time.perf_counter()
thread = backend.validate_object("CommentThread", thread_id)
log.info(f"{prefix} Thread fetch {time.perf_counter() - start_time} sec")
except ObjectDoesNotExist as exc:
log.error("Forumv2RequestError for delete thread request.")
raise ForumV2RequestError(
f"Thread does not exist with Id: {thread_id}"
) from exc
start_time = time.perf_counter()
backend.delete_comments_of_a_thread(thread_id)
log.info(f"{prefix} Delete comments of thread {time.perf_counter() - start_time} sec")
try:
start_time = time.perf_counter()
serialized_data = prepare_thread_api_response(thread, backend)
log.info(f"{prefix} Prepare response {time.perf_counter() - start_time} sec")
except ValidationError as error:
log.error(f"Validation error in get_thread: {error}")
raise ForumV2RequestError("Failed to prepare thread API response") from error
start_time = time.perf_counter()
backend.delete_subscriptions_of_a_thread(thread_id)
log.info(f"{prefix} Delete subscriptions {time.perf_counter() - start_time} sec")
start_time = time.perf_counter()
result = backend.delete_thread(thread_id)
log.info(f"{prefix} Delete thread {time.perf_counter() - start_time} sec")
if result and not (thread["anonymous"] or thread["anonymous_to_peers"]):
start_time = time.perf_counter()
backend.update_stats_for_course(
thread["author_id"], thread["course_id"], threads=-1
)
log.info(f"{prefix} Update stats {time.perf_counter() - start_time} sec")
return serialized_data
@classmethod
def delete_user_threads(cls, user_id, course_ids):
"""
@@ -264,7 +314,7 @@ class Thread(models.Model):
thread_id = thread.get("_id")
course_id = thread.get("course_id")
if thread_id:
forum_api.delete_thread(thread_id, course_id=course_id)
cls._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}")