From ba6e3f4a0e2d19afa82665c5b8d7d668bf2f74df Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 5 Feb 2018 15:05:21 -0800 Subject: [PATCH] gracefully handle bad connection errors to replica db ref #3212 --- app/models/post.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 685911222..21005a2c6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1226,6 +1226,8 @@ class Post < ApplicationRecord end count ? count.to_i : nil + rescue PG::ConnectionBad + return nil end def fast_count_search_batched(tags, options) @@ -1243,6 +1245,9 @@ class Post < ApplicationRecord end end sum + + rescue PG::ConnectionBad + return nil end def fix_post_counts(post) @@ -1673,7 +1678,11 @@ class Post < ApplicationRecord end if read_only - PostQueryBuilder.new(query).build(PostReadOnly.where("true")) + begin + PostQueryBuilder.new(query).build(PostReadOnly.where("true")) + rescue PG::ConnectionBad + PostQueryBuilder.new(query).build + end else PostQueryBuilder.new(query).build end