Commit fcf57a8e by John Eskew

Merge pull request #5370 from edx/jeskew/wrap_studio_views_in_bulk_ops

Wrap studio views in bulk operations to minimize mongo calls.
parents ed68b0ab 46cd9b0a
......@@ -141,6 +141,7 @@ def container_handler(request, usage_key_string):
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
usage_key = UsageKey.from_string(usage_key_string)
with modulestore().bulk_operations(usage_key.course_key):
try:
course, xblock, lms_link = _get_item_in_course(request, usage_key)
except ItemNotFoundError:
......
......@@ -212,7 +212,9 @@ def course_handler(request, course_key_string=None):
response_format = request.REQUEST.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
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))
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)
......@@ -248,6 +250,7 @@ def course_rerun_handler(request, course_key_string):
if not GlobalStaff().has_user(request.user):
raise PermissionDenied()
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)
if request.method == 'GET':
return render_to_response('course-create-rerun.html', {
......@@ -644,9 +647,9 @@ def course_info_handler(request, course_key_string):
html: return html for editing the course info handouts and updates.
"""
course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
return render_to_response(
'course_info.html',
{
......@@ -727,6 +730,7 @@ def settings_handler(request, course_key_string):
json: update the Course and About xblocks through the CourseDetails model
"""
course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user)
if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
upload_asset_url = reverse_course_url('assets_handler', course_key)
......@@ -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)
"""
course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user)
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):
metadata dicts.
"""
course_key = CourseKey.from_string(course_key_string)
with modulestore().bulk_operations(course_key):
course_module = _get_course_module(course_key, request.user)
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):
json: overwrite all textbooks in the course with the given list
"""
course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
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'):
# return HTML page
......@@ -1079,8 +1086,9 @@ def textbooks_detail_handler(request, course_key_string, textbook_id):
json: remove textbook
"""
course_key = CourseKey.from_string(course_key_string)
course_module = _get_course_module(course_key, request.user)
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
if unicode(tb.get("id")) == unicode(textbook_id)]
if matching_id:
......@@ -1314,8 +1322,9 @@ def group_configurations_list_handler(request, course_key_string):
json: create new group configuration
"""
course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
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'):
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
json: update group configuration based on provided information
"""
course_key = CourseKey.from_string(course_key_string)
course = _get_course_module(course_key, request.user)
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
if unicode(p.id) == unicode(group_configuration_id)]
if matching_id:
......
......@@ -461,6 +461,7 @@ def _create_item(request):
raise PermissionDenied()
store = modulestore()
with store.bulk_operations(usage_key.course_key):
parent = store.get_item(usage_key)
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_
Duplicate an existing xblock as a child of the supplied parent_usage_key.
"""
store = modulestore()
with store.bulk_operations(duplicate_source_usage_key.course_key):
source_item = store.get_item(duplicate_source_usage_key)
# Change the blockID to be unique.
dest_usage_key = source_item.location.replace(name=uuid4().hex)
......@@ -571,6 +573,7 @@ def _delete_item(usage_key, user):
"""
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
# 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
......@@ -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.
"""
store = modulestore()
with store.bulk_operations(usage_key.course_key):
try:
return store.get_item(usage_key, depth=None)
except ItemNotFoundError:
......@@ -636,6 +640,7 @@ def _get_module_info(xblock, rewrite_static_links=True):
metadata, data, id representation of a leaf module fetcher.
:param usage_key: A UsageKey
"""
with modulestore().bulk_operations(xblock.location.course_key):
data = getattr(xblock, 'data', '')
if rewrite_static_links:
data = replace_static_urls(
......
......@@ -722,7 +722,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
course_entry = self._lookup_course(course_id)
root = course_entry['structure']['root']
result = self._load_items(course_entry, [root], 0, lazy=True, **kwargs)
result = self._load_items(course_entry, [root], depth, lazy=True, **kwargs)
return result[0]
def has_course(self, course_id, ignore_case=False, **kwargs):
......
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