Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-submissions
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-submissions
Commits
5ad00f0e
Commit
5ad00f0e
authored
Aug 10, 2017
by
Eric Fischer
Committed by
GitHub
Aug 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70 from edx/efischer/slice_all
Use sliced all() in management command
parents
110a6e0b
3906fa7e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
9 deletions
+17
-9
setup.py
+1
-1
submissions/management/commands/update_submissions_uuids.py
+15
-8
submissions/models.py
+1
-0
No files found.
setup.py
View file @
5ad00f0e
...
@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
...
@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
setup
(
setup
(
name
=
'edx-submissions'
,
name
=
'edx-submissions'
,
version
=
'2.0.1
0
'
,
version
=
'2.0.1
1
'
,
author
=
'edX'
,
author
=
'edX'
,
description
=
'An API for creating submissions and scores.'
,
description
=
'An API for creating submissions and scores.'
,
url
=
'http://github.com/edx/edx-submissions.git'
,
url
=
'http://github.com/edx/edx-submissions.git'
,
...
...
submissions/management/commands/update_submissions_uuids.py
View file @
5ad00f0e
...
@@ -14,11 +14,13 @@ import time
...
@@ -14,11 +14,13 @@ import time
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
from
django.db
import
transaction
from
django.db
import
transaction
from
django.db.models
import
Max
from
submissions.models
import
Submission
from
submissions.models
import
Submission
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
"""
Example usage: ./manage.py lms --settings=devstack update_submissions_uuids.py
Example usage: ./manage.py lms --settings=devstack update_submissions_uuids.py
...
@@ -35,16 +37,19 @@ class Command(BaseCommand):
...
@@ -35,16 +37,19 @@ class Command(BaseCommand):
parser
.
add_argument
(
parser
.
add_argument
(
'--start'
,
'-s'
,
'--start'
,
'-s'
,
default
=
0
,
default
=
0
,
type
=
int
,
help
=
u"The Submission.id at which to begin updating rows. 0 by default."
help
=
u"The Submission.id at which to begin updating rows. 0 by default."
)
)
parser
.
add_argument
(
parser
.
add_argument
(
'--chunk'
,
'-c'
,
'--chunk'
,
'-c'
,
default
=
1000
,
default
=
1000
,
type
=
int
,
help
=
u"Batch size, how many rows to update in a given transaction. Default 1000."
,
help
=
u"Batch size, how many rows to update in a given transaction. Default 1000."
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
'--wait'
,
'-w'
,
'--wait'
,
'-w'
,
default
=
2
,
default
=
2
,
type
=
int
,
help
=
u"Wait time between transactions, in seconds. Default 2."
,
help
=
u"Wait time between transactions, in seconds. Default 2."
,
)
)
...
@@ -53,15 +58,17 @@ class Command(BaseCommand):
...
@@ -53,15 +58,17 @@ class Command(BaseCommand):
By default, we're going to do this in chunks. This way, if there ends up being an error,
By default, we're going to do this in chunks. This way, if there ends up being an error,
we can check log messages and continue from that point after fixing the issue.
we can check log messages and continue from that point after fixing the issue.
"""
"""
total_len
=
Submission
.
objects
.
count
()
# Note that by taking last_id here, we're going to miss any submissions created *during* the command execution
log
.
info
(
"Beginning uuid update, {} rows exist in total"
.
format
(
total_len
))
# But that's okay! All new entries have already been created using the new style, no acion needed there
last_id
=
Submission
.
_objects
.
all
()
.
aggregate
(
Max
(
'id'
))[
'id__max'
]
log
.
info
(
"Beginning uuid update"
)
current
=
options
[
'start'
]
;
current
=
options
[
'start'
]
while
current
<
total_len
:
while
current
<
last_id
:
end_chunk
=
current
+
options
[
'chunk'
]
if
total_len
-
options
[
'chunk'
]
>=
current
else
total_len
end_chunk
=
current
+
options
[
'chunk'
]
if
last_id
-
options
[
'chunk'
]
>=
current
else
last_id
log
.
info
(
"Updating entries in range [{}, {}
)
"
.
format
(
current
,
end_chunk
))
log
.
info
(
"Updating entries in range [{}, {}
]
"
.
format
(
current
,
end_chunk
))
with
transaction
.
atomic
():
with
transaction
.
atomic
():
for
submission
in
Submission
.
objects
.
filter
(
id__gte
=
current
,
id__lt
=
end_chunk
)
.
iterator
():
for
submission
in
Submission
.
_objects
.
filter
(
id__gte
=
current
,
id__lte
=
end_chunk
)
.
iterator
():
submission
.
save
(
update_fields
=
[
'uuid'
])
submission
.
save
(
update_fields
=
[
'uuid'
])
time
.
sleep
(
options
[
'wait'
])
time
.
sleep
(
options
[
'wait'
])
current
=
current
+
options
[
'chunk'
]
current
=
end_chunk
+
1
submissions/models.py
View file @
5ad00f0e
...
@@ -140,6 +140,7 @@ class Submission(models.Model):
...
@@ -140,6 +140,7 @@ class Submission(models.Model):
return
super
(
Submission
.
SoftDeletedManager
,
self
)
.
get_queryset
()
.
exclude
(
status
=
Submission
.
DELETED
)
return
super
(
Submission
.
SoftDeletedManager
,
self
)
.
get_queryset
()
.
exclude
(
status
=
Submission
.
DELETED
)
objects
=
SoftDeletedManager
()
objects
=
SoftDeletedManager
()
_objects
=
models
.
Manager
()
# Don't use this unless you know and can explain why objects doesn't work for you
@staticmethod
@staticmethod
def
get_cache_key
(
sub_uuid
):
def
get_cache_key
(
sub_uuid
):
...
...
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