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
bfd29571
Commit
bfd29571
authored
11 years ago
by
Greg Price
Browse files
Options
Downloads
Plain Diff
Merge pull request #1457 from edx/gprice/add-newrelic-instrumentation
Add newrelic instrumentation to forum views
parents
f3bcef2f
85f5c932
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lms/djangoapps/django_comment_client/forum/views.py
+53
-29
53 additions, 29 deletions
lms/djangoapps/django_comment_client/forum/views.py
with
53 additions
and
29 deletions
lms/djangoapps/django_comment_client/forum/views.py
+
53
−
29
View file @
bfd29571
...
...
@@ -6,6 +6,7 @@ from django.contrib.auth.decorators import login_required
from
django.http
import
Http404
from
django.core.context_processors
import
csrf
from
django.contrib.auth.models
import
User
import
newrelic.agent
from
mitxmako.shortcuts
import
render_to_response
from
courseware.courses
import
get_course_with_access
...
...
@@ -25,7 +26,7 @@ escapedict = {'"': '"'}
log
=
logging
.
getLogger
(
"
edx.discussions
"
)
@
login_required
@
newrelic.agent.function_trace
()
def
get_threads
(
request
,
course_id
,
discussion_id
=
None
,
per_page
=
THREADS_PER_PAGE
):
"""
This may raise cc.utils.CommentClientError or
...
...
@@ -108,6 +109,8 @@ def inline_discussion(request, course_id, discussion_id):
"""
Renders JSON for DiscussionModules
"""
nr_transaction
=
newrelic
.
agent
.
current_transaction
()
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
try
:
...
...
@@ -118,7 +121,8 @@ def inline_discussion(request, course_id, discussion_id):
log
.
error
(
"
Error loading inline discussion threads.
"
)
raise
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_metadata_for_threads
"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
allow_anonymous
=
course
.
allow_anonymous
allow_anonymous_to_peers
=
course
.
allow_anonymous_to_peers
...
...
@@ -165,9 +169,11 @@ def forum_form_discussion(request, course_id):
"""
Renders the main Discussion page, potentially filtered by a search query
"""
nr_transaction
=
newrelic
.
agent
.
current_transaction
()
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
category_map
=
utils
.
get_discussion_category_map
(
course
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_discussion_category_map
"
):
category_map
=
utils
.
get_discussion_category_map
(
course
)
try
:
unsafethreads
,
query_params
=
get_threads
(
request
,
course_id
)
# This might process a search query
...
...
@@ -182,12 +188,15 @@ def forum_form_discussion(request, course_id):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user_info
=
user
.
to_dict
()
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_metadata_for_threads
"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
add_courseware_context_to_threads
"
):
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
.
update
(
courseware_context
)
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
.
update
(
courseware_context
)
if
request
.
is_ajax
():
return
utils
.
JsonResponse
({
'
discussion_data
'
:
threads
,
# TODO: Standardize on 'discussion_data' vs 'threads'
...
...
@@ -205,10 +214,11 @@ def forum_form_discussion(request, course_id):
#trending_tags = cc.search_trending_tags(
# course_id,
#)
cohorts
=
get_course_cohorts
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_cohort_info
"
):
cohorts
=
get_course_cohorts
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
user_cohort_id
=
get_cohort_id
(
request
.
user
,
course_id
)
user_cohort_id
=
get_cohort_id
(
request
.
user
,
course_id
)
context
=
{
'
csrf
'
:
csrf
(
request
)[
'
csrf_token
'
],
...
...
@@ -236,6 +246,8 @@ def forum_form_discussion(request, course_id):
@login_required
def
single_thread
(
request
,
course_id
,
discussion_id
,
thread_id
):
nr_transaction
=
newrelic
.
agent
.
current_transaction
()
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user_info
=
cc_user
.
to_dict
()
...
...
@@ -247,8 +259,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
raise
if
request
.
is_ajax
():
courseware_context
=
get_courseware_context
(
thread
,
course
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_courseware_context
"
):
courseware_context
=
get_courseware_context
(
thread
,
course
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_annotated_content_infos
"
):
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
context
=
{
'
thread
'
:
thread
.
to_dict
(),
'
course_id
'
:
course_id
}
# TODO: Remove completely or switch back to server side rendering
# html = render_to_string('discussion/_ajax_single_thread.html', context)
...
...
@@ -262,7 +276,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
})
else
:
category_map
=
utils
.
get_discussion_category_map
(
course
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_discussion_category_map
"
):
category_map
=
utils
.
get_discussion_category_map
(
course
)
try
:
threads
,
query_params
=
get_threads
(
request
,
course_id
)
...
...
@@ -273,16 +288,17 @@ def single_thread(request, course_id, discussion_id, thread_id):
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
.
update
(
courseware_context
)
if
thread
.
get
(
'
group_id
'
)
and
not
thread
.
get
(
'
group_name
'
):
thread
[
'
group_name
'
]
=
get_cohort_by_id
(
course_id
,
thread
.
get
(
'
group_id
'
)).
name
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
add_courseware_context_to_threads
"
):
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
.
update
(
courseware_context
)
if
thread
.
get
(
'
group_id
'
)
and
not
thread
.
get
(
'
group_name
'
):
thread
[
'
group_name
'
]
=
get_cohort_by_id
(
course_id
,
thread
.
get
(
'
group_id
'
)).
name
#patch for backward compatibility with comments service
if
not
"
pinned
"
in
thread
:
thread
[
"
pinned
"
]
=
False
#patch for backward compatibility with comments service
if
not
"
pinned
"
in
thread
:
thread
[
"
pinned
"
]
=
False
threads
=
[
utils
.
safe_content
(
thread
)
for
thread
in
threads
]
...
...
@@ -296,11 +312,13 @@ def single_thread(request, course_id, discussion_id, thread_id):
# course_id,
#)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_metadata_for_threads
"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
cohorts
=
get_course_cohorts
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
user_cohort
=
get_cohort_id
(
request
.
user
,
course_id
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_cohort_info
"
):
cohorts
=
get_course_cohorts
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
user_cohort
=
get_cohort_id
(
request
.
user
,
course_id
)
context
=
{
'
discussion_id
'
:
discussion_id
,
...
...
@@ -330,6 +348,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
@login_required
def
user_profile
(
request
,
course_id
,
user_id
):
nr_transaction
=
newrelic
.
agent
.
current_transaction
()
#TODO: Allow sorting?
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
try
:
...
...
@@ -345,7 +365,8 @@ def user_profile(request, course_id, user_id):
query_params
[
'
num_pages
'
]
=
num_pages
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
).
to_dict
()
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_metadata_for_threads
"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
if
request
.
is_ajax
():
return
utils
.
JsonResponse
({
...
...
@@ -373,6 +394,8 @@ def user_profile(request, course_id, user_id):
@login_required
def
followed_threads
(
request
,
course_id
,
user_id
):
nr_transaction
=
newrelic
.
agent
.
current_transaction
()
course
=
get_course_with_access
(
request
.
user
,
course_id
,
'
load_forum
'
)
try
:
profiled_user
=
cc
.
User
(
id
=
user_id
,
course_id
=
course_id
)
...
...
@@ -389,7 +412,8 @@ def followed_threads(request, course_id, user_id):
query_params
[
'
num_pages
'
]
=
num_pages
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
).
to_dict
()
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"
get_metadata_for_threads
"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
if
request
.
is_ajax
():
return
utils
.
JsonResponse
({
'
annotated_content_info
'
:
annotated_content_info
,
...
...
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