Commit 6fde063f authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Use Set object instead of {}.compare_by_identity

parent 33d1ae4d
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
# hosts - The list of secondary hosts to add. # hosts - The list of secondary hosts to add.
def initialize(hosts = []) def initialize(hosts = [])
@hosts = hosts.shuffle @hosts = hosts.shuffle
@pools = {}.compare_by_identity @pools = Set.new
@index = 0 @index = 0
@mutex = Mutex.new @mutex = Mutex.new
@hosts_gauge = Gitlab::Metrics.gauge(:db_load_balancing_hosts, 'Current number of load balancing hosts') @hosts_gauge = Gitlab::Metrics.gauge(:db_load_balancing_hosts, 'Current number of load balancing hosts')
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
end end
def manage_pool?(pool) def manage_pool?(pool)
@pools[pool] == true @pools.include?(pool)
end end
def hosts=(hosts) def hosts=(hosts)
...@@ -80,9 +80,7 @@ module Gitlab ...@@ -80,9 +80,7 @@ module Gitlab
end end
def update_pools def update_pools
@pools = @hosts.each_with_object({}.compare_by_identity) do |host, flags| @pools = Set.new(@hosts.map(&:pool))
flags[host.pool] = true
end
end end
end end
end end
......
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