Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Remove unused and often misleading options
Browse files Browse the repository at this point in the history
In the following cases we were passing options around but never using
them, perhaps leftover from a previous implementation.

I've removed them so the code is more explicit and hopefully a little
less confusing.
  • Loading branch information
mriddle committed Mar 27, 2020
1 parent ff0b673 commit 6915462
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/global_uid/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def global_uid_disabled
@global_uid_disabled
end

def generate_uid(options = {})
GlobalUid::Base.get_uid_for_class(self, options)
def generate_uid
GlobalUid::Base.get_uid_for_class(self)
end

def generate_many_uids(count, options = {})
GlobalUid::Base.get_many_uids_for_class(self, count, options)
def generate_many_uids(count)
GlobalUid::Base.get_many_uids_for_class(self, count)
end

def disable_global_uid
Expand Down
32 changes: 16 additions & 16 deletions lib/global_uid/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.create_uid_tables(id_table_name, options={})
end
end

def self.drop_uid_tables(id_table_name, options={})
def self.drop_uid_tables(id_table_name)
with_connections do |connection|
connection.execute("DROP TABLE IF EXISTS `#{id_table_name}`")
end
Expand All @@ -70,11 +70,12 @@ def self.new_connection(name, connection_timeout)
end
end

def self.init_server_info(options)
def self.init_server_info
id_servers = self.global_uid_servers
increment_by = self.global_uid_increment_by

raise "You haven't configured any id servers" if id_servers.nil? or id_servers.empty?
raise "More servers configured than increment_by: #{id_servers.size} > #{options[:increment_by]} -- this will create duplicate IDs." if id_servers.size > options[:increment_by]
raise "More servers configured than increment_by: #{id_servers.size} > #{increment_by} -- this will create duplicate IDs." if id_servers.size > increment_by

id_servers.map do |name, i|
info = {}
Expand All @@ -83,7 +84,7 @@ def self.init_server_info(options)
info[:retry_at] = nil
info[:rand] = rand
info[:new?] = true
info[:allocated_ids] = Allocations.new(incrementing_by: self.global_uid_increment_by)
info[:allocated_ids] = Allocations.new(incrementing_by: increment_by)
info
end
end
Expand All @@ -92,12 +93,12 @@ def self.disconnect!
self.servers = nil
end

def self.setup_connections!(options)
connection_timeout = options[:connection_timeout]
increment_by = options[:increment_by]
def self.setup_connections!
connection_timeout = self.global_uid_options[:connection_timeout]
increment_by = self.global_uid_increment_by

if self.servers.nil?
self.servers = init_server_info(options)
self.servers = init_server_info
# sorting here sets up each process to have affinity to a particular server.
self.servers = self.servers.sort_by { |s| s[:rand] }
end
Expand All @@ -115,7 +116,7 @@ def self.setup_connections!(options)
end

info[:cx] = connection
info[:retry_at] = Time.now + options[:connection_retry] if connection.nil?
info[:retry_at] = Time.now + self.global_uid_options[:connection_retry] if connection.nil?
rescue InvalidIncrementPreventionException => e
notify e, "#{e.message}"
info[:cx] = nil
Expand All @@ -126,11 +127,10 @@ def self.setup_connections!(options)
self.servers
end

def self.with_connections(options = {})
options = self.global_uid_options.merge(options)
servers = setup_connections!(options)
def self.with_connections
servers = setup_connections!

if !options[:per_process_affinity]
if !self.global_uid_options[:per_process_affinity]
servers = servers.sort_by { rand } #yes, I know it's not true random.
end

Expand Down Expand Up @@ -165,7 +165,7 @@ def self.notify(exception, message)
end
end

def self.get_connections(options = {})
def self.get_connections
with_connections {}
end

Expand All @@ -177,7 +177,7 @@ def self.validate_increment!(new_record_id, connection)
end
end

def self.get_uid_for_class(klass, options = {})
def self.get_uid_for_class(klass)
with_connections do |connection|
Timeout.timeout(self.global_uid_options[:query_timeout], TimeoutException) do
id = connection.insert("REPLACE INTO #{klass.global_uid_table} (stub) VALUES ('a')")
Expand All @@ -188,7 +188,7 @@ def self.get_uid_for_class(klass, options = {})
raise NoServersAvailableException, "All global UID servers are gone!"
end

def self.get_many_uids_for_class(klass, count, options = {})
def self.get_many_uids_for_class(klass, count)
return [] unless count > 0
with_connections do |connection|
Timeout.timeout(self.global_uid_options[:query_timeout], TimeoutException) do
Expand Down
2 changes: 1 addition & 1 deletion lib/global_uid/migration_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_table(name, options = {}, &blk)
def drop_table(name, options = {})
if !GlobalUid::Base.global_uid_options[:disabled] && options[:use_global_uid] == true
id_table_name = options[:global_uid_table] || GlobalUid::Base.id_table_from_name(name)
GlobalUid::Base.drop_uid_tables(id_table_name,options)
GlobalUid::Base.drop_uid_tables(id_table_name)
end
super(name, options)
end
Expand Down

0 comments on commit 6915462

Please sign in to comment.