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
85f5c932
Commit
85f5c932
authored
Oct 22, 2013
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add newrelic instrumentation to forum views
parent
60306f24
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
28 deletions
+53
-28
lms/djangoapps/django_comment_client/forum/views.py
+53
-28
No files found.
lms/djangoapps/django_comment_client/forum/views.py
View file @
85f5c932
...
@@ -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,6 +26,7 @@ escapedict = {'"': '"'}
...
@@ -25,6 +26,7 @@ escapedict = {'"': '"'}
log
=
logging
.
getLogger
(
"edx.discussions"
)
log
=
logging
.
getLogger
(
"edx.discussions"
)
@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
...
@@ -107,6 +109,8 @@ def inline_discussion(request, course_id, discussion_id):
...
@@ -107,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
:
...
@@ -120,7 +124,8 @@ def inline_discussion(request, course_id, discussion_id):
...
@@ -120,7 +124,8 @@ def inline_discussion(request, course_id, discussion_id):
log
.
error
(
"Error loading inline discussion threads."
)
log
.
error
(
"Error loading inline discussion threads."
)
raise
Http404
raise
Http404
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
...
@@ -167,9 +172,11 @@ def forum_form_discussion(request, course_id):
...
@@ -167,9 +172,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
...
@@ -184,12 +191,15 @@ def forum_form_discussion(request, course_id):
...
@@ -184,12 +191,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'
...
@@ -207,10 +217,11 @@ def forum_form_discussion(request, course_id):
...
@@ -207,10 +217,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'
],
...
@@ -238,6 +249,8 @@ def forum_form_discussion(request, course_id):
...
@@ -238,6 +249,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
()
...
@@ -249,8 +262,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -249,8 +262,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
raise
Http404
raise
Http404
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)
...
@@ -264,7 +279,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -264,7 +279,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
)
...
@@ -275,16 +291,17 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -275,16 +291,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
]
...
@@ -298,11 +315,13 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -298,11 +315,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
,
...
@@ -332,6 +351,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -332,6 +351,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
:
...
@@ -347,7 +368,8 @@ def user_profile(request, course_id, user_id):
...
@@ -347,7 +368,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
({
...
@@ -374,6 +396,8 @@ def user_profile(request, course_id, user_id):
...
@@ -374,6 +396,8 @@ def user_profile(request, course_id, user_id):
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
)
...
@@ -390,7 +414,8 @@ def followed_threads(request, course_id, user_id):
...
@@ -390,7 +414,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