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