Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
30476a33
Commit
30476a33
authored
6 years ago
by
Eric Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Stop hitting mongo so much, cache this result
parent
1828bf7d
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/django_comment_client/tests/test_utils.py
+2
-0
2 additions, 0 deletions
lms/djangoapps/django_comment_client/tests/test_utils.py
lms/djangoapps/django_comment_client/utils.py
+12
-4
12 additions, 4 deletions
lms/djangoapps/django_comment_client/utils.py
with
14 additions
and
4 deletions
lms/djangoapps/django_comment_client/tests/test_utils.py
+
2
−
0
View file @
30476a33
...
...
@@ -38,6 +38,7 @@ from openedx.core.djangoapps.content.course_structures.models import CourseStruc
from
openedx.core.djangoapps.course_groups
import
cohorts
from
openedx.core.djangoapps.course_groups.cohorts
import
set_course_cohorted
from
openedx.core.djangoapps.course_groups.tests.helpers
import
CohortFactory
,
config_course_cohorts
from
openedx.core.djangoapps.request_cache.middleware
import
RequestCache
from
openedx.core.djangoapps.util.testing
import
ContentGroupTestCase
from
student.roles
import
CourseStaffRole
from
student.tests.factories
import
AdminFactory
,
CourseEnrollmentFactory
,
UserFactory
...
...
@@ -1785,6 +1786,7 @@ class GroupModeratorPermissionsTestCase(ModuleStoreTestCase):
'
can_vote
'
:
True
,
'
can_report
'
:
True
})
RequestCache
.
clear_request_cache
()
set_discussion_division_settings
(
self
.
course
.
id
,
division_scheme
=
CourseDiscussionSettings
.
ENROLLMENT_TRACK
)
content
=
{
'
user_id
'
:
self
.
verified_user
.
id
,
'
type
'
:
'
thread
'
,
'
username
'
:
self
.
verified_user
.
username
}
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/django_comment_client/utils.py
+
12
−
4
View file @
30476a33
...
...
@@ -592,15 +592,14 @@ def get_user_group_ids(course_id, content, user=None):
content_user_group_id
=
None
user_group_id
=
None
if
course_id
is
not
None
:
course_discussion_settings
=
get_course_discussion_settings
(
course_id
)
if
content
.
get
(
'
username
'
):
try
:
content_user
=
get_user_by_username_or_email
(
content
.
get
(
'
username
'
))
content_user_group_id
=
get_group_id_for_user
(
content_user
,
course_d
iscussion_settings
)
content_user_group_id
=
get_group_id_for_user
_from_cache
(
content_user
,
course_
i
d
)
except
User
.
DoesNotExist
:
content_user_group_id
=
None
user_group_id
=
get_group_id_for_user
(
user
,
course_d
iscussion_settings
)
if
user
else
None
user_group_id
=
get_group_id_for_user
_from_cache
(
user
,
course_
i
d
)
if
user
else
None
return
user_group_id
,
content_user_group_id
...
...
@@ -819,7 +818,7 @@ def get_group_id_for_comments_service(request, course_key, commentable_id=None):
_verify_group_exists
(
group_id
,
course_discussion_settings
)
else
:
# regular users always query with their own id.
group_id
=
get_group_id_for_user
(
request
.
user
,
course_
discussion_settings
)
group_id
=
get_group_id_for_user
_from_cache
(
request
.
user
,
course_
key
)
return
group_id
else
:
# Never pass a group_id to the comments service for a non-divided
...
...
@@ -827,6 +826,15 @@ def get_group_id_for_comments_service(request, course_key, commentable_id=None):
return
None
@request_cached
def
get_group_id_for_user_from_cache
(
user
,
course_id
):
"""
Caches the results of get_group_id_for_user, but serializes the course_id
instead of the course_discussions_settings object as cache keys.
"""
return
get_group_id_for_user
(
user
,
get_course_discussion_settings
(
course_id
))
def
get_group_id_for_user
(
user
,
course_discussion_settings
):
"""
Given a user, return the group_id for that user according to the course_discussion_settings.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment