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
3906fa7e
Commit
3906fa7e
authored
Aug 09, 2017
by
Eric Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use sliced all() in management command
parent
110a6e0b
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 @
3906fa7e
...
...
@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
setup
(
name
=
'edx-submissions'
,
version
=
'2.0.1
0
'
,
version
=
'2.0.1
1
'
,
author
=
'edX'
,
description
=
'An API for creating submissions and scores.'
,
url
=
'http://github.com/edx/edx-submissions.git'
,
...
...
submissions/management/commands/update_submissions_uuids.py
View file @
3906fa7e
...
...
@@ -14,11 +14,13 @@ import time
from
django.core.management.base
import
BaseCommand
from
django.db
import
transaction
from
django.db.models
import
Max
from
submissions.models
import
Submission
log
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
"""
Example usage: ./manage.py lms --settings=devstack update_submissions_uuids.py
...
...
@@ -35,16 +37,19 @@ class Command(BaseCommand):
parser
.
add_argument
(
'--start'
,
'-s'
,
default
=
0
,
type
=
int
,
help
=
u"The Submission.id at which to begin updating rows. 0 by default."
)
parser
.
add_argument
(
'--chunk'
,
'-c'
,
default
=
1000
,
type
=
int
,
help
=
u"Batch size, how many rows to update in a given transaction. Default 1000."
,
)
parser
.
add_argument
(
'--wait'
,
'-w'
,
default
=
2
,
type
=
int
,
help
=
u"Wait time between transactions, in seconds. Default 2."
,
)
...
...
@@ -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,
we can check log messages and continue from that point after fixing the issue.
"""
total_len
=
Submission
.
objects
.
count
()
log
.
info
(
"Beginning uuid update, {} rows exist in total"
.
format
(
total_len
))
# Note that by taking last_id here, we're going to miss any submissions created *during* the command execution
# 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'
]
;
while
current
<
total_len
:
end_chunk
=
current
+
options
[
'chunk'
]
if
total_len
-
options
[
'chunk'
]
>=
current
else
total_len
log
.
info
(
"Updating entries in range [{}, {}
)
"
.
format
(
current
,
end_chunk
))
current
=
options
[
'start'
]
while
current
<
last_id
:
end_chunk
=
current
+
options
[
'chunk'
]
if
last_id
-
options
[
'chunk'
]
>=
current
else
last_id
log
.
info
(
"Updating entries in range [{}, {}
]
"
.
format
(
current
,
end_chunk
))
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'
])
time
.
sleep
(
options
[
'wait'
])
current
=
current
+
options
[
'chunk'
]
current
=
end_chunk
+
1
submissions/models.py
View file @
3906fa7e
...
...
@@ -140,6 +140,7 @@ class Submission(models.Model):
return
super
(
Submission
.
SoftDeletedManager
,
self
)
.
get_queryset
()
.
exclude
(
status
=
Submission
.
DELETED
)
objects
=
SoftDeletedManager
()
_objects
=
models
.
Manager
()
# Don't use this unless you know and can explain why objects doesn't work for you
@staticmethod
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