Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
a7c82214
Commit
a7c82214
authored
Mar 21, 2017
by
Matjaz Gregoric
Committed by
GitHub
Mar 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #145 from open-craft/mtyaka/copy-course-ids-management-without-count
Avoid count(*) query in management command.
parents
c559a665
4c2009be
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
9 deletions
+11
-9
circle.yml
+1
-1
problem_builder/management/commands/copy_deprecated_course_id.py
+9
-7
setup.py
+1
-1
No files found.
circle.yml
View file @
a7c82214
...
@@ -11,7 +11,7 @@ dependencies:
...
@@ -11,7 +11,7 @@ dependencies:
-
"
pip
install
-r
requirements.txt"
-
"
pip
install
-r
requirements.txt"
-
"
pip
install
-r
$VIRTUAL_ENV/src/xblock-sdk/requirements/base.txt"
-
"
pip
install
-r
$VIRTUAL_ENV/src/xblock-sdk/requirements/base.txt"
-
"
pip
install
-r
$VIRTUAL_ENV/src/xblock-sdk/requirements/test.txt"
-
"
pip
install
-r
$VIRTUAL_ENV/src/xblock-sdk/requirements/test.txt"
-
"
pip
uninstall
-y
xblock-problem-builder
&&
python
setup.py
sdist
&&
pip
install
dist/xblock-problem-builder-2.6.
8
.tar.gz"
-
"
pip
uninstall
-y
xblock-problem-builder
&&
python
setup.py
sdist
&&
pip
install
dist/xblock-problem-builder-2.6.
9
.tar.gz"
-
"
pip
install
-r
test_requirements.txt"
-
"
pip
install
-r
test_requirements.txt"
-
"
mkdir
var"
-
"
mkdir
var"
test
:
test
:
...
...
problem_builder/management/commands/copy_deprecated_course_id.py
View file @
a7c82214
import
math
import
time
import
time
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
from
problem_builder.models
import
Answer
from
problem_builder.models
import
Answer
...
@@ -29,18 +28,21 @@ class Command(BaseCommand):
...
@@ -29,18 +28,21 @@ class Command(BaseCommand):
batch_size
=
options
[
'batch_size'
]
batch_size
=
options
[
'batch_size'
]
sleep_time
=
options
[
'sleep'
]
sleep_time
=
options
[
'sleep'
]
queryset
=
Answer
.
objects
.
filter
(
course_key__isnull
=
True
)
queryset
=
Answer
.
objects
.
filter
(
course_key__isnull
=
True
)
batch_count
=
int
(
math
.
ceil
(
queryset
.
count
()
/
float
(
batch_size
)))
self
.
stdout
.
write
(
self
.
stdout
.
write
(
"Copying Answer.course_id field into Answer.course_key in batches of {}"
.
format
(
batch_size
)
"Copying Answer.course_id field into Answer.course_key in batches of {}"
.
format
(
batch_size
)
)
)
for
batch
in
xrange
(
1
,
batch_count
+
1
):
idx
=
0
for
answer
in
queryset
[:
batch_size
]:
while
True
:
idx
+=
1
batch
=
queryset
[:
batch_size
]
if
not
batch
:
break
for
answer
in
batch
:
answer
.
course_key
=
answer
.
course_id
answer
.
course_key
=
answer
.
course_id
answer
.
save
()
answer
.
save
()
self
.
stdout
.
write
(
"Processed batch {} of {}"
.
format
(
batch
,
batch_count
))
self
.
stdout
.
write
(
"Processed batch {}"
.
format
(
idx
))
if
batch
!=
batch_count
:
time
.
sleep
(
sleep_time
)
time
.
sleep
(
sleep_time
)
self
.
stdout
.
write
(
"Successfully copied Answer.course_id into Answer.course_key"
)
self
.
stdout
.
write
(
"Successfully copied Answer.course_id into Answer.course_key"
)
setup.py
View file @
a7c82214
...
@@ -71,7 +71,7 @@ BLOCKS = [
...
@@ -71,7 +71,7 @@ BLOCKS = [
setup
(
setup
(
name
=
'xblock-problem-builder'
,
name
=
'xblock-problem-builder'
,
version
=
'2.6.
8
'
,
version
=
'2.6.
9
'
,
description
=
'XBlock - Problem Builder'
,
description
=
'XBlock - Problem Builder'
,
packages
=
[
'problem_builder'
,
'problem_builder.v1'
],
packages
=
[
'problem_builder'
,
'problem_builder.v1'
],
install_requires
=
[
install_requires
=
[
...
...
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