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
94e98e9c
Commit
94e98e9c
authored
Jun 03, 2015
by
Ali Mohammad
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8257 from edx/alawibaba/plat589
Make clean_history.py use the StudentHistoryModule django model.
parents
416dd82d
36e5fcf4
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 @
94e98e9c
...
@@ -16,7 +16,9 @@ import time
...
@@ -16,7 +16,9 @@ import time
import
traceback
import
traceback
from
django.core.management.base
import
NoArgsCommand
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
):
class
Command
(
NoArgsCommand
):
...
@@ -72,7 +74,7 @@ class StudentModuleHistoryCleaner(object):
...
@@ -72,7 +74,7 @@ class StudentModuleHistoryCleaner(object):
batch_size
=
batch_size
or
self
.
BATCH_SIZE
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
.
last_student_module_id
=
self
.
get_last_student_module_id
()
self
.
load_state
()
self
.
load_state
()
...
@@ -104,7 +106,7 @@ class StudentModuleHistoryCleaner(object):
...
@@ -104,7 +106,7 @@ class StudentModuleHistoryCleaner(object):
Commit the transaction.
Commit the transaction.
"""
"""
self
.
say
(
"Committing"
)
self
.
say
(
"Committing"
)
conne
ction
.
commit
()
transa
ction
.
commit
()
def
load_state
(
self
):
def
load_state
(
self
):
"""
"""
...
@@ -140,11 +142,8 @@ class StudentModuleHistoryCleaner(object):
...
@@ -140,11 +142,8 @@ class StudentModuleHistoryCleaner(object):
"""
"""
Return the id of the last student_module.
Return the id of the last student_module.
"""
"""
cursor
=
connection
.
cursor
()
last
=
StudentModuleHistory
.
objects
.
all
()
\
cursor
.
execute
(
"""
.
aggregate
(
Max
(
'student_module'
))[
'student_module__max'
]
SELECT max(student_module_id) FROM courseware_studentmodulehistory
"""
)
last
=
cursor
.
fetchone
()[
0
]
self
.
say
(
"Last student_module_id is {}"
.
format
(
last
))
self
.
say
(
"Last student_module_id is {}"
.
format
(
last
))
return
last
return
last
...
@@ -176,17 +175,11 @@ class StudentModuleHistoryCleaner(object):
...
@@ -176,17 +175,11 @@ class StudentModuleHistoryCleaner(object):
Return a list: [(id, created), ...], all the rows of history.
Return a list: [(id, created), ...], all the rows of history.
"""
"""
cursor
=
connection
.
cursor
()
history
=
StudentModuleHistory
.
objects
\
cursor
.
execute
(
.
filter
(
student_module
=
student_module_id
)
\
"""
.
order_by
(
'created'
,
'id'
)
SELECT id, created FROM courseware_studentmodulehistory
WHERE student_module_id =
%
s
return
[(
row
.
id
,
row
.
created
)
for
row
in
history
]
ORDER BY created, id
"""
,
[
student_module_id
]
)
history
=
cursor
.
fetchall
()
return
history
def
delete_history
(
self
,
ids_to_delete
):
def
delete_history
(
self
,
ids_to_delete
):
"""
"""
...
@@ -196,13 +189,7 @@ class StudentModuleHistoryCleaner(object):
...
@@ -196,13 +189,7 @@ class StudentModuleHistoryCleaner(object):
"""
"""
assert
ids_to_delete
assert
ids_to_delete
cursor
=
connection
.
cursor
()
StudentModuleHistory
.
objects
.
filter
(
id__in
=
ids_to_delete
)
.
delete
()
cursor
.
execute
(
"""
DELETE FROM courseware_studentmodulehistory
WHERE id IN ({ids})
"""
.
format
(
ids
=
","
.
join
(
str
(
i
)
for
i
in
ids_to_delete
))
)
def
clean_one_student_module
(
self
,
student_module_id
):
def
clean_one_student_module
(
self
,
student_module_id
):
"""Clean one StudentModule's-worth of history.
"""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