use replica db for calculating post counts

This commit is contained in:
r888888888
2016-01-28 18:31:03 -08:00
parent e6b16e8fe5
commit 81684e6421
2 changed files with 13 additions and 4 deletions

View File

@@ -1,4 +1,13 @@
class PostReadOnly < Post
establish_connection "ro_#{Rails.env}".to_sym
attr_readonly *column_names
def with_timeout(n, default_value = nil)
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
yield
rescue ::ActiveRecord::StatementInvalid => x
return default_value
ensure
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
end
end