Commit e3776863 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'pl-fix-lint-hash-compare-by-identity' into 'master'

Fix RuboCop offenses for Lint/HashCompareByIdentity

See merge request gitlab-org/gitlab!56186
parents c828bbf7 ce3cd71e
...@@ -2518,7 +2518,3 @@ Style/ClassEqualityComparison: ...@@ -2518,7 +2518,3 @@ Style/ClassEqualityComparison:
Exclude: Exclude:
- spec/lib/peek/views/active_record_spec.rb - spec/lib/peek/views/active_record_spec.rb
- ee/spec/lib/peek/views/active_record_spec.rb - ee/spec/lib/peek/views/active_record_spec.rb
Lint/HashCompareByIdentity:
Exclude:
- ee/lib/gitlab/database/load_balancing/load_balancer.rb
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
# hosts - The hostnames/addresses of the additional databases. # hosts - The hostnames/addresses of the additional databases.
def initialize(hosts = []) def initialize(hosts = [])
@host_list = HostList.new(hosts.map { |addr| Host.new(addr, self) }) @host_list = HostList.new(hosts.map { |addr| Host.new(addr, self) })
@connection_db_roles = {} @connection_db_roles = {}.compare_by_identity
end end
# Yields a connection that can be used for reads. # Yields a connection that can be used for reads.
...@@ -34,11 +34,11 @@ module Gitlab ...@@ -34,11 +34,11 @@ module Gitlab
begin begin
connection = host.connection connection = host.connection
@connection_db_roles[connection.object_id] = ROLE_REPLICA @connection_db_roles[connection] = ROLE_REPLICA
return yield connection return yield connection
rescue => error rescue => error
@connection_db_roles.delete(connection.object_id) if connection.present? @connection_db_roles.delete(connection) if connection.present?
if serialization_failure?(error) if serialization_failure?(error)
# This error can occur when a query conflicts. See # This error can occur when a query conflicts. See
...@@ -83,7 +83,7 @@ module Gitlab ...@@ -83,7 +83,7 @@ module Gitlab
read_write(&block) read_write(&block)
ensure ensure
@connection_db_roles.delete(connection.object_id) if connection.present? @connection_db_roles.delete(connection) if connection.present?
end end
# Yields a connection that can be used for both reads and writes. # Yields a connection that can be used for both reads and writes.
...@@ -94,19 +94,19 @@ module Gitlab ...@@ -94,19 +94,19 @@ module Gitlab
# a few times. # a few times.
retry_with_backoff do retry_with_backoff do
connection = ActiveRecord::Base.retrieve_connection connection = ActiveRecord::Base.retrieve_connection
@connection_db_roles[connection.object_id] = ROLE_PRIMARY @connection_db_roles[connection] = ROLE_PRIMARY
yield connection yield connection
end end
ensure ensure
@connection_db_roles.delete(connection.object_id) if connection.present? @connection_db_roles.delete(connection) if connection.present?
end end
# Recognize the role (primary/replica) of the database this connection # Recognize the role (primary/replica) of the database this connection
# is connecting to. If the connection is not issued by this load # is connecting to. If the connection is not issued by this load
# balancer, return nil # balancer, return nil
def db_role_for_connection(connection) def db_role_for_connection(connection)
@connection_db_roles[connection.object_id] @connection_db_roles[connection]
end end
# Returns a host to use for queries. # Returns a host to use for queries.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment