Commit 1b3efaba by Waheed Ahmed

Merge pull request #8457 from edx/waheed/tnl2425-fix-slow-transaction-xblock-outline

Fixed slow transaction on xblock outline handler.
parents 2092d732 b328c0dc
......@@ -332,13 +332,14 @@ def xblock_outline_handler(request, usage_key_string):
response_format = request.REQUEST.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
store = modulestore()
root_xblock = store.get_item(usage_key)
return JsonResponse(create_xblock_info(
root_xblock,
include_child_info=True,
course_outline=True,
include_children_predicate=lambda xblock: not xblock.category == 'vertical'
))
with store.bulk_operations(usage_key.course_key):
root_xblock = store.get_item(usage_key)
return JsonResponse(create_xblock_info(
root_xblock,
include_child_info=True,
course_outline=True,
include_children_predicate=lambda xblock: not xblock.category == 'vertical'
))
else:
return Http404
......
......@@ -1410,6 +1410,28 @@ class TestXBlockInfo(ItemTest):
json_response = json.loads(resp.content)
self.validate_course_xblock_info(json_response, course_outline=True)
def test_xblock_outline_handler_mongo_calls(self):
expected_calls = 5
with self.store.default_store(ModuleStoreEnum.Type.split):
course = CourseFactory.create()
chapter = ItemFactory.create(
parent_location=course.location, category='chapter', display_name='Week 1'
)
outline_url = reverse_usage_url('xblock_outline_handler', chapter.location)
with check_mongo_calls(expected_calls):
self.client.get(outline_url, HTTP_ACCEPT='application/json')
sequential = ItemFactory.create(
parent_location=chapter.location, category='sequential', display_name='Sequential 1'
)
ItemFactory.create(
parent_location=sequential.location, category='vertical', display_name='Vertical 1'
)
# calls should be same after adding two new children.
with check_mongo_calls(expected_calls):
self.client.get(outline_url, HTTP_ACCEPT='application/json')
def test_entrance_exam_chapter_xblock_info(self):
chapter = ItemFactory.create(
parent_location=self.course.location, category='chapter', display_name="Entrance Exam",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment