lib/pgbouncerhero/connection.rb in pgbouncerhero-0.1.0 vs lib/pgbouncerhero/connection.rb in pgbouncerhero-0.1.1

- old
+ new

@@ -8,21 +8,23 @@ @password = password @dbname = dbname end def connection - begin - PG.connect( - host: @host, - port: @port, - user: @user, - password: @password, - dbname: @dbname, - connect_timeout: 5 - ) - rescue => e - Rails.logger.info(e) - nil + @connection ||= begin + begin + PG.connect( + host: @host, + port: @port, + user: @user, + password: @password, + dbname: @dbname, + connect_timeout: 5 + ) + rescue => e + Rails.logger.info(e) + nil + end end end end end