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
cfa034ba
Commit
cfa034ba
authored
Dec 02, 2015
by
Adam
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10785 from edx/adam/delete-orphans-in-bulk-op
do orphan deletion in a bulk operation (SUST-21)
parents
06eede5d
72e7ac5d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
cms/djangoapps/contentstore/tests/test_orphan.py
+14
-8
cms/djangoapps/contentstore/views/item.py
+7
-6
No files found.
cms/djangoapps/contentstore/tests/test_orphan.py
View file @
cfa034ba
...
...
@@ -10,7 +10,7 @@ from opaque_keys.edx.locator import BlockUsageLocator
from
student.models
import
CourseEnrollment
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.search
import
path_to_location
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
check_mongo_calls_range
class
TestOrphanBase
(
CourseTestCase
):
...
...
@@ -93,21 +93,27 @@ class TestOrphan(TestOrphanBase):
)
self
.
assertEqual
(
len
(
orphans
),
3
,
"Wrong # {}"
.
format
(
orphans
))
location
=
course
.
location
.
replace
(
category
=
'chapter'
,
name
=
'OrphanChapter'
)
self
.
assertIn
(
location
.
to_deprecated_string
(
),
orphans
)
self
.
assertIn
(
unicode
(
location
),
orphans
)
location
=
course
.
location
.
replace
(
category
=
'vertical'
,
name
=
'OrphanVert'
)
self
.
assertIn
(
location
.
to_deprecated_string
(
),
orphans
)
self
.
assertIn
(
unicode
(
location
),
orphans
)
location
=
course
.
location
.
replace
(
category
=
'html'
,
name
=
'OrphanHtml'
)
self
.
assertIn
(
location
.
to_deprecated_string
(),
orphans
)
@ddt.data
(
ModuleStoreEnum
.
Type
.
split
,
ModuleStoreEnum
.
Type
.
mongo
)
def
test_delete_orphans
(
self
,
default_store
):
self
.
assertIn
(
unicode
(
location
),
orphans
)
@ddt.data
(
(
ModuleStoreEnum
.
Type
.
split
,
9
,
6
),
(
ModuleStoreEnum
.
Type
.
mongo
,
30
,
13
),
)
@ddt.unpack
def
test_delete_orphans
(
self
,
default_store
,
max_mongo_calls
,
min_mongo_calls
):
"""
Test that the orphan handler deletes the orphans
"""
course
=
self
.
create_course_with_orphans
(
default_store
)
orphan_url
=
reverse_course_url
(
'orphan_handler'
,
course
.
id
)
self
.
client
.
delete
(
orphan_url
)
with
check_mongo_calls_range
(
max_mongo_calls
,
min_mongo_calls
):
self
.
client
.
delete
(
orphan_url
)
orphans
=
json
.
loads
(
self
.
client
.
get
(
orphan_url
,
HTTP_ACCEPT
=
'application/json'
)
.
content
)
...
...
cms/djangoapps/contentstore/views/item.py
View file @
cfa034ba
...
...
@@ -693,12 +693,13 @@ def _delete_orphans(course_usage_key, user_id, commit=False):
items
=
store
.
get_orphans
(
course_usage_key
)
branch
=
course_usage_key
.
branch
if
commit
:
for
itemloc
in
items
:
revision
=
ModuleStoreEnum
.
RevisionOption
.
all
# specify branches when deleting orphans
if
branch
==
ModuleStoreEnum
.
BranchName
.
published
:
revision
=
ModuleStoreEnum
.
RevisionOption
.
published_only
store
.
delete_item
(
itemloc
,
user_id
,
revision
=
revision
)
with
store
.
bulk_operations
(
course_usage_key
):
for
itemloc
in
items
:
revision
=
ModuleStoreEnum
.
RevisionOption
.
all
# specify branches when deleting orphans
if
branch
==
ModuleStoreEnum
.
BranchName
.
published
:
revision
=
ModuleStoreEnum
.
RevisionOption
.
published_only
store
.
delete_item
(
itemloc
,
user_id
,
revision
=
revision
)
return
[
unicode
(
item
)
for
item
in
items
]
...
...
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