From 76718c70121f4f05d5398f33c087c55cc5f156ef Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 9 Jul 2015 18:15:48 -0700 Subject: [PATCH] add details to newrelic trace, fix 401 errors for xml --- app/controllers/application_controller.rb | 4 ++++ app/models/post.rb | 2 +- config/initializers/active_record_extensions.rb | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1fb787fe8..f848a9521 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -58,6 +58,10 @@ protected render :text => "authentication failed", :status => 401 end + fmt.xml do + render :xml => {:sucess => false, :reason => "authentication failed"}.to_xml(:root => "response"), :status => 401 + end + fmt.json do render :json => {:success => false, :reason => "authentication failed"}.to_json, :status => 401 end diff --git a/app/models/post.rb b/app/models/post.rb index 3ff3ece6a..6b67ea0d6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1034,7 +1034,7 @@ class Post < ActiveRecord::Base end def fast_count_search(tags, options = {}) - count = Post.with_timeout(options[:statement_timeout] || 500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do + count = Post.with_timeout(options[:statement_timeout] || 500, Danbooru.config.blank_tag_search_fast_count || 1_000_000, :tags => tags) do Post.tag_match(tags).count end if count > 0 diff --git a/config/initializers/active_record_extensions.rb b/config/initializers/active_record_extensions.rb index 1908ef905..602ae6b88 100644 --- a/config/initializers/active_record_extensions.rb +++ b/config/initializers/active_record_extensions.rb @@ -11,12 +11,12 @@ module Danbooru connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test" end - def with_timeout(n, default_value = nil) + def with_timeout(n, default_value = nil, new_relic_params = {}) connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test" yield rescue ::ActiveRecord::StatementInvalid => x if Rails.env.production? - NewRelic::Agent.notice_error(x, :custom_params => {:user_id => CurrentUser.user.id, :user_ip_addr => CurrentUser.ip_addr}) + NewRelic::Agent.notice_error(x, :custom_params => new_relic_params.merge(:user_id => CurrentUser.user.id, :user_ip_addr => CurrentUser.ip_addr)) end return default_value ensure