From 9f90799f276a5ff2eeda5e7233554da9b1b39397 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 15 Nov 2017 17:00:37 -0800 Subject: [PATCH] fix newrelic handler for statement timeouts --- app/models/tag.rb | 9 +++------ config/initializers/active_record_extensions.rb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index ba0fc7586..7d0b0ddb0 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -141,12 +141,9 @@ class Tag < ApplicationRecord Post.with_timeout(30_000, nil, {:tags => name}) do Post.raw_tag_match(name).where("true /* Tag#update_category_post_counts */").find_each do |post| post.reload - # sometimes a post gets expunged - if post - post.set_tag_counts(false) - args = TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}.to_h.update(:tag_count => post.tag_count) - Post.where(:id => post.id).update_all(args) - end + post.set_tag_counts(false) + args = TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}.to_h.update(:tag_count => post.tag_count) + Post.where(:id => post.id).update_all(args) end end end diff --git a/config/initializers/active_record_extensions.rb b/config/initializers/active_record_extensions.rb index 360f558b0..c4270c5a3 100644 --- a/config/initializers/active_record_extensions.rb +++ b/config/initializers/active_record_extensions.rb @@ -16,7 +16,7 @@ module Danbooru yield rescue ::ActiveRecord::StatementInvalid => x if Rails.env.production? - NewRelic::Agent.notice_error(x, :custom_params => new_relic_params.merge(: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.id, :user_ip_addr => CurrentUser.ip_addr)) end return default_value ensure