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
36e5fcf4
Commit
36e5fcf4
authored
May 28, 2015
by
alawibaba
Committed by
Ali Mohammad
May 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make clean_history.py use the StudentHistoryModule django model.
parent
0a43ebf1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
26 deletions
+13
-26
lms/djangoapps/courseware/management/commands/clean_history.py
+13
-26
No files found.
lms/djangoapps/courseware/management/commands/clean_history.py
View file @
36e5fcf4
...
...
@@ -16,7 +16,9 @@ import time
import
traceback
from
django.core.management.base
import
NoArgsCommand
from
django.db
import
connection
from
django.db
import
transaction
from
django.db.models
import
Max
from
courseware.models
import
StudentModuleHistory
class
Command
(
NoArgsCommand
):
...
...
@@ -72,7 +74,7 @@ class StudentModuleHistoryCleaner(object):
batch_size
=
batch_size
or
self
.
BATCH_SIZE
conne
ction
.
enter_transaction_management
()
transa
ction
.
enter_transaction_management
()
self
.
last_student_module_id
=
self
.
get_last_student_module_id
()
self
.
load_state
()
...
...
@@ -104,7 +106,7 @@ class StudentModuleHistoryCleaner(object):
Commit the transaction.
"""
self
.
say
(
"Committing"
)
conne
ction
.
commit
()
transa
ction
.
commit
()
def
load_state
(
self
):
"""
...
...
@@ -140,11 +142,8 @@ class StudentModuleHistoryCleaner(object):
"""
Return the id of the last student_module.
"""
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT max(student_module_id) FROM courseware_studentmodulehistory
"""
)
last
=
cursor
.
fetchone
()[
0
]
last
=
StudentModuleHistory
.
objects
.
all
()
\
.
aggregate
(
Max
(
'student_module'
))[
'student_module__max'
]
self
.
say
(
"Last student_module_id is {}"
.
format
(
last
))
return
last
...
...
@@ -176,17 +175,11 @@ class StudentModuleHistoryCleaner(object):
Return a list: [(id, created), ...], all the rows of history.
"""
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT id, created FROM courseware_studentmodulehistory
WHERE student_module_id =
%
s
ORDER BY created, id
"""
,
[
student_module_id
]
)
history
=
cursor
.
fetchall
()
return
history
history
=
StudentModuleHistory
.
objects
\
.
filter
(
student_module
=
student_module_id
)
\
.
order_by
(
'created'
,
'id'
)
return
[(
row
.
id
,
row
.
created
)
for
row
in
history
]
def
delete_history
(
self
,
ids_to_delete
):
"""
...
...
@@ -196,13 +189,7 @@ class StudentModuleHistoryCleaner(object):
"""
assert
ids_to_delete
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
DELETE FROM courseware_studentmodulehistory
WHERE id IN ({ids})
"""
.
format
(
ids
=
","
.
join
(
str
(
i
)
for
i
in
ids_to_delete
))
)
StudentModuleHistory
.
objects
.
filter
(
id__in
=
ids_to_delete
)
.
delete
()
def
clean_one_student_module
(
self
,
student_module_id
):
"""Clean one StudentModule's-worth of history.
...
...
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