Commit d2473e9e by jimabramson

add newrelic traces to pinpoint bottlenecks

parent 8cec6a36
require 'new_relic/agent/method_tracer'
get "#{APIPREFIX}/search/threads" do
sort_key_mapper = {
......@@ -50,12 +52,16 @@ get "#{APIPREFIX}/search/threads" do
num_pages = results.total_pages
page = [num_pages, [1, page].max].min
{
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
get "#{APIPREFIX}/search/threads/more_like_this" do
......
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)
{
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
......
......@@ -182,12 +182,16 @@ helpers do
collection = pres_threads.to_hash_array(bool_recursive)
end
{
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
def author_contents_only(contents, author_id)
......@@ -286,4 +290,13 @@ helpers do
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
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 = 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,12 +160,14 @@ class CommentThread < Content
#use the elasticsearch index instead to avoid DB hit
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'
......@@ -302,4 +309,7 @@ private
subscriptions.delete_all
end
include ::NewRelic::Agent::MethodTracer
add_method_tracer :perform_search
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment