Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
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
cs_comments_service
Commits
d2473e9e
Commit
d2473e9e
authored
Oct 29, 2013
by
jimabramson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add newrelic traces to pinpoint bottlenecks
parent
8cec6a36
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
28 deletions
+63
-28
api/search.rb
+11
-5
api/users.rb
+11
-5
lib/helpers.rb
+18
-5
models/comment_thread.rb
+23
-13
No files found.
api/search.rb
View file @
d2473e9e
require
'new_relic/agent/method_tracer'
get
"
#{
APIPREFIX
}
/search/threads"
do
sort_key_mapper
=
{
...
...
@@ -50,11 +52,15 @@ get "#{APIPREFIX}/search/threads" do
num_pages
=
results
.
total_pages
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
json_output
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/get_search_threads/json_serialize'
])
do
json_output
=
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
end
json_output
end
end
...
...
api/users.rb
View file @
d2473e9e
require
'new_relic/agent/method_tracer'
post
"
#{
APIPREFIX
}
/users"
do
user
=
User
.
new
(
external_id:
params
[
"id"
])
user
.
username
=
params
[
"username"
]
...
...
@@ -43,11 +45,15 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
collection
=
presenter
.
to_hash_array
(
true
)
collection
=
author_contents_only
(
collection
,
user_id
)
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
json_output
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/get_user_active_threads/json_serialize'
])
do
json_output
=
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
end
json_output
end
...
...
lib/helpers.rb
View file @
d2473e9e
...
...
@@ -182,11 +182,15 @@ helpers do
collection
=
pres_threads
.
to_hash_array
(
bool_recursive
)
end
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
json_output
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/handle_threads_query/json_serialize'
])
do
json_output
=
{
collection:
collection
,
num_pages:
num_pages
,
page:
page
,
}.
to_json
end
json_output
end
end
...
...
@@ -285,5 +289,14 @@ helpers do
error
503
end
end
include
::
NewRelic
::
Agent
::
MethodTracer
add_method_tracer
:user
add_method_tracer
:thread
add_method_tracer
:comment
add_method_tracer
:flag_as_abuse
add_method_tracer
:unflag_as_abuse
add_method_tracer
:author_contents_only
add_method_tracer
:handle_threads_query
end
models/comment_thread.rb
View file @
d2473e9e
require
'new_relic/agent/method_tracer'
require_relative
'content'
class
CommentThread
<
Content
...
...
@@ -143,11 +144,15 @@ class CommentThread < Content
#unforutnately, we cannot paginate here, b/c we don't know how the ordinality is totally
#unrelated to that of threads
c_results
=
search
.
results
comment_ids
=
c_results
.
collect
{
|
c
|
c
.
id
}.
uniq
comments
=
Comment
.
where
(
:id
.
in
=>
comment_ids
)
thread_ids
=
comments
.
collect
{
|
c
|
c
.
comment_thread_id
}
c_results
=
comment_ids
=
comments
=
thread_ids
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/perform_search/collect_comment_search_results'
])
do
c_results
=
search
.
results
comment_ids
=
c_results
.
collect
{
|
c
|
c
.
id
}.
uniq
end
self
.
class
.
trace_execution_scoped
([
'Custom/perform_search/collect_comment_thread_ids'
])
do
comments
=
Comment
.
where
(
:id
.
in
=>
comment_ids
)
thread_ids
=
comments
.
collect
{
|
c
|
c
.
comment_thread_id
}
end
#thread_ids = c_results.collect{|c| c.comment_thread_id}
#as soon as we can add comment thread id to the ES index, via Tire updgrade, we'll
...
...
@@ -155,13 +160,15 @@ class CommentThread < Content
#use the elasticsearch index instead to avoid DB hit
original_thread_ids
=
results
.
collect
{
|
r
|
r
.
id
}
#now add the original search thread ids
thread_ids
+=
original_thread_ids
thread_ids
=
thread_ids
.
uniq
self
.
class
.
trace_execution_scoped
([
'Custom/perform_search/collect_unique_thread_ids'
])
do
original_thread_ids
=
results
.
collect
{
|
r
|
r
.
id
}
#now add the original search thread ids
thread_ids
+=
original_thread_ids
thread_ids
=
thread_ids
.
uniq
end
#now run one more search to harvest the threads and filter by group
search
=
Tire
::
Search
::
Search
.
new
'comment_threads'
search
.
filter
(
:terms
,
:thread_id
=>
thread_ids
)
...
...
@@ -301,5 +308,8 @@ private
def
destroy_subscriptions
subscriptions
.
delete_all
end
include
::
NewRelic
::
Agent
::
MethodTracer
add_method_tracer
:perform_search
end
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