diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-05-15 15:32:49 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-05-15 15:32:49 +0200 |
commit | 61ceb45088d9bfb04890866718f87686bfb5f3c1 (patch) | |
tree | ed4b4ae8a4acc0824a7bd034cc17c5dec6b05728 /config | |
parent | ba07c9f7f599cecac2c0840484f8bfc62d9e716b (diff) | |
download | gitlab-ce-61ceb45088d9bfb04890866718f87686bfb5f3c1.tar.gz |
Fix.
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/attr_encrypted_no_db_connection.rb | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/config/initializers/attr_encrypted_no_db_connection.rb b/config/initializers/attr_encrypted_no_db_connection.rb index e270028f45d..c668864089b 100644 --- a/config/initializers/attr_encrypted_no_db_connection.rb +++ b/config/initializers/attr_encrypted_no_db_connection.rb @@ -2,27 +2,19 @@ module AttrEncrypted module Adapters module ActiveRecord def attribute_instance_methods_as_symbols_with_no_db_connection - if connection_established? + # Use with_connection so the connection doesn't stay pinned to the thread. + connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false + + if connected # Call version from AttrEncrypted::Adapters::ActiveRecord attribute_instance_methods_as_symbols_without_no_db_connection else - # Call version from AttrEncrypted (`super` with regards to AttrEncrypted::Adapters::ActiveRecord) + # Call version from AttrEncrypted, i.e., `super` with regards to AttrEncrypted::Adapters::ActiveRecord AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call end end alias_method_chain :attribute_instance_methods_as_symbols, :no_db_connection - - private - - def connection_established? - begin - # Use with_connection so the connection doesn't stay pinned to the thread. - ActiveRecord::Base.connection_pool.with_connection { |con| con.active? } - rescue Exception - false - end - end end end end |