Avoid fetching full group list repeatedly
This commit is contained in:
@@ -41,6 +41,7 @@ from django_comment_client.utils import (
|
||||
is_commentable_divided,
|
||||
strip_none
|
||||
)
|
||||
from django_comment_common.models import CourseDiscussionSettings
|
||||
from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings
|
||||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
||||
from openedx.core.djangoapps.monitoring_utils import function_trace
|
||||
@@ -204,10 +205,20 @@ def inline_discussion(request, course_key, discussion_id):
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_key, threads, request.user, user_info)
|
||||
|
||||
is_staff = has_permission(request.user, 'openclose_thread', course.id)
|
||||
threads = [utils.prepare_content(thread, course_key, is_staff) for thread in threads]
|
||||
course_discussion_settings = get_course_discussion_settings(course.id)
|
||||
group_names_by_id = get_group_names_by_id(course_discussion_settings)
|
||||
course_is_divided = course_discussion_settings.division_scheme is not CourseDiscussionSettings.NONE
|
||||
threads = [
|
||||
utils.prepare_content(
|
||||
thread,
|
||||
course_key,
|
||||
is_staff,
|
||||
course_is_divided,
|
||||
group_names_by_id
|
||||
) for thread in threads
|
||||
]
|
||||
with function_trace("add_courseware_context"):
|
||||
add_courseware_context(threads, course, request.user)
|
||||
course_discussion_settings = get_course_discussion_settings(course.id)
|
||||
|
||||
return utils.JsonResponse({
|
||||
'is_commentable_divided': is_commentable_divided(course_key, discussion_id),
|
||||
|
||||
@@ -712,7 +712,7 @@ def add_courseware_context(content_list, course, user, id_map=None):
|
||||
content.update({"courseware_url": url, "courseware_title": title})
|
||||
|
||||
|
||||
def prepare_content(content, course_key, is_staff=False, discussion_division_enabled=None):
|
||||
def prepare_content(content, course_key, is_staff=False, discussion_division_enabled=None, group_names_by_id=None):
|
||||
"""
|
||||
This function is used to pre-process thread and comment models in various
|
||||
ways before adding them to the HTTP response. This includes fixing empty
|
||||
@@ -775,7 +775,13 @@ def prepare_content(content, course_key, is_staff=False, discussion_division_ena
|
||||
for child_content_key in ["children", "endorsed_responses", "non_endorsed_responses"]:
|
||||
if child_content_key in content:
|
||||
children = [
|
||||
prepare_content(child, course_key, is_staff, discussion_division_enabled=discussion_division_enabled)
|
||||
prepare_content(
|
||||
child,
|
||||
course_key,
|
||||
is_staff,
|
||||
discussion_division_enabled=discussion_division_enabled,
|
||||
group_names_by_id=group_names_by_id
|
||||
)
|
||||
for child in content[child_content_key]
|
||||
]
|
||||
content[child_content_key] = children
|
||||
@@ -784,7 +790,10 @@ def prepare_content(content, course_key, is_staff=False, discussion_division_ena
|
||||
# Augment the specified thread info to include the group name if a group id is present.
|
||||
if content.get('group_id') is not None:
|
||||
course_discussion_settings = get_course_discussion_settings(course_key)
|
||||
content['group_name'] = get_group_name(content.get('group_id'), course_discussion_settings)
|
||||
if group_names_by_id:
|
||||
content['group_name'] = group_names_by_id.get(content.get('group_id'))
|
||||
else:
|
||||
content['group_name'] = get_group_name(content.get('group_id'), course_discussion_settings)
|
||||
content['is_commentable_divided'] = is_commentable_divided(
|
||||
course_key, content['commentable_id'], course_discussion_settings
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user