Commit 46cd9b0a by John Eskew

Add bulk_operations wrapper around all course-query-intensive Studio views.

parent 2f060733
...@@ -141,6 +141,7 @@ def container_handler(request, usage_key_string): ...@@ -141,6 +141,7 @@ def container_handler(request, usage_key_string):
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
usage_key = UsageKey.from_string(usage_key_string) usage_key = UsageKey.from_string(usage_key_string)
with modulestore().bulk_operations(usage_key.course_key):
try: try:
course, xblock, lms_link = _get_item_in_course(request, usage_key) course, xblock, lms_link = _get_item_in_course(request, usage_key)
except ItemNotFoundError: except ItemNotFoundError:
......
...@@ -212,7 +212,9 @@ def course_handler(request, course_key_string=None): ...@@ -212,7 +212,9 @@ def course_handler(request, course_key_string=None):
response_format = request.REQUEST.get('format', 'html') response_format = request.REQUEST.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
if request.method == 'GET': if request.method == 'GET':
course_module = _get_course_module(CourseKey.from_string(course_key_string), request.user, depth=None) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user, depth=None)
return JsonResponse(_course_outline_json(request, course_module)) return JsonResponse(_course_outline_json(request, course_module))
elif request.method == 'POST': # not sure if this is only post. If one will have ids, it goes after access elif request.method == 'POST': # not sure if this is only post. If one will have ids, it goes after access
return _create_or_rerun_course(request) return _create_or_rerun_course(request)
...@@ -248,6 +250,7 @@ def course_rerun_handler(request, course_key_string): ...@@ -248,6 +250,7 @@ def course_rerun_handler(request, course_key_string):
if not GlobalStaff().has_user(request.user): if not GlobalStaff().has_user(request.user):
raise PermissionDenied() raise PermissionDenied()
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user, depth=3) course_module = _get_course_module(course_key, request.user, depth=3)
if request.method == 'GET': if request.method == 'GET':
return render_to_response('course-create-rerun.html', { return render_to_response('course-create-rerun.html', {
...@@ -644,9 +647,9 @@ def course_info_handler(request, course_key_string): ...@@ -644,9 +647,9 @@ def course_info_handler(request, course_key_string):
html: return html for editing the course info handouts and updates. html: return html for editing the course info handouts and updates.
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user) course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
return render_to_response( return render_to_response(
'course_info.html', 'course_info.html',
{ {
...@@ -727,6 +730,7 @@ def settings_handler(request, course_key_string): ...@@ -727,6 +730,7 @@ def settings_handler(request, course_key_string):
json: update the Course and About xblocks through the CourseDetails model json: update the Course and About xblocks through the CourseDetails model
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user) course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET': if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
upload_asset_url = reverse_course_url('assets_handler', course_key) upload_asset_url = reverse_course_url('assets_handler', course_key)
...@@ -781,6 +785,7 @@ def grading_handler(request, course_key_string, grader_index=None): ...@@ -781,6 +785,7 @@ def grading_handler(request, course_key_string, grader_index=None):
json w/ grader_index: create or update the specific grader (create if index out of range) json w/ grader_index: create or update the specific grader (create if index out of range)
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user) course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET': if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
...@@ -892,6 +897,7 @@ def advanced_settings_handler(request, course_key_string): ...@@ -892,6 +897,7 @@ def advanced_settings_handler(request, course_key_string):
metadata dicts. metadata dicts.
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user) course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET': if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
...@@ -1004,8 +1010,9 @@ def textbooks_list_handler(request, course_key_string): ...@@ -1004,8 +1010,9 @@ def textbooks_list_handler(request, course_key_string):
json: overwrite all textbooks in the course with the given list json: overwrite all textbooks in the course with the given list
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
store = modulestore() store = modulestore()
with store.bulk_operations(course_key):
course = _get_course_module(course_key, request.user)
if not "application/json" in request.META.get('HTTP_ACCEPT', 'text/html'): if not "application/json" in request.META.get('HTTP_ACCEPT', 'text/html'):
# return HTML page # return HTML page
...@@ -1079,8 +1086,9 @@ def textbooks_detail_handler(request, course_key_string, textbook_id): ...@@ -1079,8 +1086,9 @@ def textbooks_detail_handler(request, course_key_string, textbook_id):
json: remove textbook json: remove textbook
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
course_module = _get_course_module(course_key, request.user)
store = modulestore() store = modulestore()
with store.bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user)
matching_id = [tb for tb in course_module.pdf_textbooks matching_id = [tb for tb in course_module.pdf_textbooks
if unicode(tb.get("id")) == unicode(textbook_id)] if unicode(tb.get("id")) == unicode(textbook_id)]
if matching_id: if matching_id:
...@@ -1314,8 +1322,9 @@ def group_configurations_list_handler(request, course_key_string): ...@@ -1314,8 +1322,9 @@ def group_configurations_list_handler(request, course_key_string):
json: create new group configuration json: create new group configuration
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
store = modulestore() store = modulestore()
with store.bulk_operations(course_key):
course = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
group_configuration_url = reverse_course_url('group_configurations_list_handler', course_key) group_configuration_url = reverse_course_url('group_configurations_list_handler', course_key)
...@@ -1364,8 +1373,9 @@ def group_configurations_detail_handler(request, course_key_string, group_config ...@@ -1364,8 +1373,9 @@ def group_configurations_detail_handler(request, course_key_string, group_config
json: update group configuration based on provided information json: update group configuration based on provided information
""" """
course_key = CourseKey.from_string(course_key_string) course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
store = modulestore() store = modulestore()
with store.bulk_operations(course_key):
course = _get_course_module(course_key, request.user)
matching_id = [p for p in course.user_partitions matching_id = [p for p in course.user_partitions
if unicode(p.id) == unicode(group_configuration_id)] if unicode(p.id) == unicode(group_configuration_id)]
if matching_id: if matching_id:
......
...@@ -461,6 +461,7 @@ def _create_item(request): ...@@ -461,6 +461,7 @@ def _create_item(request):
raise PermissionDenied() raise PermissionDenied()
store = modulestore() store = modulestore()
with store.bulk_operations(usage_key.course_key):
parent = store.get_item(usage_key) parent = store.get_item(usage_key)
dest_usage_key = usage_key.replace(category=category, name=uuid4().hex) dest_usage_key = usage_key.replace(category=category, name=uuid4().hex)
...@@ -516,6 +517,7 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_ ...@@ -516,6 +517,7 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_
Duplicate an existing xblock as a child of the supplied parent_usage_key. Duplicate an existing xblock as a child of the supplied parent_usage_key.
""" """
store = modulestore() store = modulestore()
with store.bulk_operations(duplicate_source_usage_key.course_key):
source_item = store.get_item(duplicate_source_usage_key) source_item = store.get_item(duplicate_source_usage_key)
# Change the blockID to be unique. # Change the blockID to be unique.
dest_usage_key = source_item.location.replace(name=uuid4().hex) dest_usage_key = source_item.location.replace(name=uuid4().hex)
...@@ -571,6 +573,7 @@ def _delete_item(usage_key, user): ...@@ -571,6 +573,7 @@ def _delete_item(usage_key, user):
""" """
store = modulestore() store = modulestore()
with store.bulk_operations(usage_key.course_key):
# VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so # VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so
# if we add one then we need to also add it to the policy information (i.e. metadata) # if we add one then we need to also add it to the policy information (i.e. metadata)
# we should remove this once we can break this reference from the course to static tabs # we should remove this once we can break this reference from the course to static tabs
...@@ -618,6 +621,7 @@ def _get_xblock(usage_key, user): ...@@ -618,6 +621,7 @@ def _get_xblock(usage_key, user):
in the CREATE_IF_NOT_FOUND list, an xblock will be created and saved automatically. in the CREATE_IF_NOT_FOUND list, an xblock will be created and saved automatically.
""" """
store = modulestore() store = modulestore()
with store.bulk_operations(usage_key.course_key):
try: try:
return store.get_item(usage_key, depth=None) return store.get_item(usage_key, depth=None)
except ItemNotFoundError: except ItemNotFoundError:
...@@ -636,6 +640,7 @@ def _get_module_info(xblock, rewrite_static_links=True): ...@@ -636,6 +640,7 @@ def _get_module_info(xblock, rewrite_static_links=True):
metadata, data, id representation of a leaf module fetcher. metadata, data, id representation of a leaf module fetcher.
:param usage_key: A UsageKey :param usage_key: A UsageKey
""" """
with modulestore().bulk_operations(xblock.location.course_key):
data = getattr(xblock, 'data', '') data = getattr(xblock, 'data', '')
if rewrite_static_links: if rewrite_static_links:
data = replace_static_urls( data = replace_static_urls(
......
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