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
d382f569
Commit
d382f569
authored
Feb 27, 2015
by
Usman Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor django_comment_client.utils.prepare_content() to query
course cohort settings only once. TNL-1258
parent
a9e0082c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
12 deletions
+24
-12
lms/djangoapps/django_comment_client/forum/tests.py
+10
-8
lms/djangoapps/django_comment_client/tests/test_utils.py
+0
-1
lms/djangoapps/django_comment_client/utils.py
+14
-3
No files found.
lms/djangoapps/django_comment_client/forum/tests.py
View file @
d382f569
...
@@ -309,18 +309,18 @@ class SingleThreadTestCase(ModuleStoreTestCase):
...
@@ -309,18 +309,18 @@ class SingleThreadTestCase(ModuleStoreTestCase):
@patch
(
'requests.request'
)
@patch
(
'requests.request'
)
class
SingleThreadQueryCountTestCase
(
ModuleStoreTestCase
):
class
SingleThreadQueryCountTestCase
(
ModuleStoreTestCase
):
"""
"""
Ensures the number of modulestore queries
is deterministic based on th
e
Ensures the number of modulestore queries
and number of sql queries ar
e
number of responses retrieved for a given discussion thread.
independent of the
number of responses retrieved for a given discussion thread.
"""
"""
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
@ddt.data
(
@ddt.data
(
# old mongo with cache: 15
# old mongo with cache: 15
(
ModuleStoreEnum
.
Type
.
mongo
,
1
,
21
,
15
),
(
ModuleStoreEnum
.
Type
.
mongo
,
1
,
21
,
15
,
30
),
(
ModuleStoreEnum
.
Type
.
mongo
,
50
,
315
,
15
),
(
ModuleStoreEnum
.
Type
.
mongo
,
50
,
315
,
15
,
30
),
# split mongo: 3 queries, regardless of thread response size.
# split mongo: 3 queries, regardless of thread response size.
(
ModuleStoreEnum
.
Type
.
split
,
1
,
3
,
3
),
(
ModuleStoreEnum
.
Type
.
split
,
1
,
3
,
3
,
30
),
(
ModuleStoreEnum
.
Type
.
split
,
50
,
3
,
3
),
(
ModuleStoreEnum
.
Type
.
split
,
50
,
3
,
3
,
30
),
)
)
@ddt.unpack
@ddt.unpack
def
test_number_of_mongo_queries
(
def
test_number_of_mongo_queries
(
...
@@ -329,6 +329,7 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
...
@@ -329,6 +329,7 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
num_thread_responses
,
num_thread_responses
,
num_uncached_mongo_calls
,
num_uncached_mongo_calls
,
num_cached_mongo_calls
,
num_cached_mongo_calls
,
num_sql_queries
,
mock_request
mock_request
):
):
with
modulestore
()
.
default_store
(
default_store
):
with
modulestore
()
.
default_store
(
default_store
):
...
@@ -377,8 +378,9 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
...
@@ -377,8 +378,9 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
for
single_thread_cache
,
expected_calls
in
cached_calls
.
items
():
for
single_thread_cache
,
expected_calls
in
cached_calls
.
items
():
single_thread_cache
.
clear
()
single_thread_cache
.
clear
()
with
patch
(
"django_comment_client.permissions.CACHE"
,
single_thread_cache
):
with
patch
(
"django_comment_client.permissions.CACHE"
,
single_thread_cache
):
with
check_mongo_calls
(
expected_calls
):
with
self
.
assertNumQueries
(
num_sql_queries
):
call_single_thread
()
with
check_mongo_calls
(
expected_calls
):
call_single_thread
()
single_thread_cache
.
clear
()
single_thread_cache
.
clear
()
...
...
lms/djangoapps/django_comment_client/tests/test_utils.py
View file @
d382f569
...
@@ -18,7 +18,6 @@ import django_comment_client.utils as utils
...
@@ -18,7 +18,6 @@ import django_comment_client.utils as utils
from
openedx.core.djangoapps.course_groups.cohorts
import
set_course_cohort_settings
from
openedx.core.djangoapps.course_groups.cohorts
import
set_course_cohort_settings
from
student.tests.factories
import
UserFactory
,
CourseEnrollmentFactory
from
student.tests.factories
import
UserFactory
,
CourseEnrollmentFactory
from
xmodule.modulestore.tests.django_utils
import
TEST_DATA_MOCK_MODULESTORE
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
d382f569
...
@@ -405,7 +405,7 @@ def add_courseware_context(content_list, course, user, id_map=None):
...
@@ -405,7 +405,7 @@ def add_courseware_context(content_list, course, user, id_map=None):
content
.
update
({
"courseware_url"
:
url
,
"courseware_title"
:
title
})
content
.
update
({
"courseware_url"
:
url
,
"courseware_title"
:
title
})
def
prepare_content
(
content
,
course_key
,
is_staff
=
False
):
def
prepare_content
(
content
,
course_key
,
is_staff
=
False
,
**
kwargs
):
"""
"""
This function is used to pre-process thread and comment models in various
This function is used to pre-process thread and comment models in various
ways before adding them to the HTTP response. This includes fixing empty
ways before adding them to the HTTP response. This includes fixing empty
...
@@ -414,6 +414,12 @@ def prepare_content(content, course_key, is_staff=False):
...
@@ -414,6 +414,12 @@ def prepare_content(content, course_key, is_staff=False):
@TODO: not all response pre-processing steps are currently integrated into
@TODO: not all response pre-processing steps are currently integrated into
this function.
this function.
Arguments:
content (dict): A thread or comment.
course_key (CourseKey): The course key of the course.
is_staff (bool): Whether the user is a staff member.
course_is_cohorted (bool): Whether the course is cohorted.
"""
"""
fields
=
[
fields
=
[
'id'
,
'title'
,
'body'
,
'course_id'
,
'anonymous'
,
'anonymous_to_peers'
,
'id'
,
'title'
,
'body'
,
'course_id'
,
'anonymous'
,
'anonymous_to_peers'
,
...
@@ -453,14 +459,19 @@ def prepare_content(content, course_key, is_staff=False):
...
@@ -453,14 +459,19 @@ def prepare_content(content, course_key, is_staff=False):
else
:
else
:
del
endorsement
[
"user_id"
]
del
endorsement
[
"user_id"
]
course_is_cohorted
=
kwargs
.
get
(
'course_is_cohorted'
)
if
course_is_cohorted
is
None
:
course_is_cohorted
=
is_course_cohorted
(
course_key
)
for
child_content_key
in
[
"children"
,
"endorsed_responses"
,
"non_endorsed_responses"
]:
for
child_content_key
in
[
"children"
,
"endorsed_responses"
,
"non_endorsed_responses"
]:
if
child_content_key
in
content
:
if
child_content_key
in
content
:
children
=
[
children
=
[
prepare_content
(
child
,
course_key
,
is_staff
)
for
child
in
content
[
child_content_key
]
prepare_content
(
child
,
course_key
,
is_staff
,
course_is_cohorted
=
course_is_cohorted
)
for
child
in
content
[
child_content_key
]
]
]
content
[
child_content_key
]
=
children
content
[
child_content_key
]
=
children
if
is_course_cohorted
(
course_key
)
:
if
course_is_cohorted
:
# Augment the specified thread info to include the group name if a group id is present.
# Augment the specified thread info to include the group name if a group id is present.
if
content
.
get
(
'group_id'
)
is
not
None
:
if
content
.
get
(
'group_id'
)
is
not
None
:
content
[
'group_name'
]
=
get_cohort_by_id
(
course_key
,
content
.
get
(
'group_id'
))
.
name
content
[
'group_name'
]
=
get_cohort_by_id
(
course_key
,
content
.
get
(
'group_id'
))
.
name
...
...
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