Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f3c898a9
Commit
f3c898a9
authored
Sep 15, 2014
by
John Eskew
Committed by
Zia Fazal
Apr 06, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bulk_operations wrapper around all course-query-intensive Studio views.
parent
6ef76489
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
6 deletions
+22
-6
cms/djangoapps/contentstore/views/component.py
+1
-0
cms/djangoapps/contentstore/views/course.py
+16
-6
cms/djangoapps/contentstore/views/item.py
+5
-0
No files found.
cms/djangoapps/contentstore/views/component.py
View file @
f3c898a9
...
@@ -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
:
...
...
cms/djangoapps/contentstore/views/course.py
View file @
f3c898a9
...
@@ -218,7 +218,9 @@ def course_handler(request, course_key_string=None):
...
@@ -218,7 +218,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
)
...
@@ -254,6 +256,7 @@ def course_rerun_handler(request, course_key_string):
...
@@ -254,6 +256,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'
,
{
...
@@ -650,9 +653,9 @@ def course_info_handler(request, course_key_string):
...
@@ -650,9 +653,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'
,
{
{
...
@@ -821,6 +824,7 @@ def settings_handler(request, course_key_string):
...
@@ -821,6 +824,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
)
...
@@ -875,6 +879,7 @@ def grading_handler(request, course_key_string, grader_index=None):
...
@@ -875,6 +879,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'
:
...
@@ -986,6 +991,7 @@ def advanced_settings_handler(request, course_key_string):
...
@@ -986,6 +991,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'
:
...
@@ -1098,8 +1104,9 @@ def textbooks_list_handler(request, course_key_string):
...
@@ -1098,8 +1104,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
...
@@ -1173,8 +1180,9 @@ def textbooks_detail_handler(request, course_key_string, textbook_id):
...
@@ -1173,8 +1180,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
:
...
@@ -1408,8 +1416,9 @@ def group_configurations_list_handler(request, course_key_string):
...
@@ -1408,8 +1416,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
)
...
@@ -1458,8 +1467,9 @@ def group_configurations_detail_handler(request, course_key_string, group_config
...
@@ -1458,8 +1467,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
:
...
...
cms/djangoapps/contentstore/views/item.py
View file @
f3c898a9
...
@@ -496,6 +496,7 @@ def _create_item(request):
...
@@ -496,6 +496,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
)
...
@@ -551,6 +552,7 @@ def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_
...
@@ -551,6 +552,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
)
...
@@ -606,6 +608,7 @@ def _delete_item(usage_key, user):
...
@@ -606,6 +608,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
...
@@ -653,6 +656,7 @@ def _get_xblock(usage_key, user):
...
@@ -653,6 +656,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
:
...
@@ -671,6 +675,7 @@ def _get_module_info(xblock, rewrite_static_links=True):
...
@@ -671,6 +675,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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment