1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Optimize stringify item before pushing it (#4575)

* Optimize stringify hashes

* Optimize symbolize hashes
This commit is contained in:
David Santos Merino 2020-05-23 00:38:52 +02:00 committed by GitHub
parent 6d1fa34616
commit 797578c591
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View file

@ -8,16 +8,14 @@ module Sidekiq
class RedisConnection
class << self
def create(options = {})
options.keys.each do |key|
options[key.to_sym] = options.delete(key)
symbolized_options = options.transform_keys(&:to_sym)
if !symbolized_options[:url] && (u = determine_redis_provider)
symbolized_options[:url] = u
end
if !options[:url] && (u = determine_redis_provider)
options[:url] = u
end
size = if options[:size]
options[:size]
size = if symbolized_options[:size]
symbolized_options[:size]
elsif Sidekiq.server?
# Give ourselves plenty of connections. pool is lazy
# so we won't create them until we need them.
@ -30,11 +28,11 @@ module Sidekiq
verify_sizing(size, Sidekiq.options[:concurrency]) if Sidekiq.server?
pool_timeout = options[:pool_timeout] || 1
log_info(options)
pool_timeout = symbolized_options[:pool_timeout] || 1
log_info(symbolized_options)
ConnectionPool.new(timeout: pool_timeout, size: size) do
build_client(options)
build_client(symbolized_options)
end
end

View file

@ -201,12 +201,9 @@ module Sidekiq
# Merge options with current params, filter safe params, and stringify to query string
def qparams(options)
# stringify
options.keys.each do |key|
options[key.to_s] = options.delete(key)
end
stringified_options = options.transform_keys(&:to_s)
to_query_string(params.merge(options))
to_query_string(params.merge(stringified_options))
end
def to_query_string(params)

View file

@ -235,12 +235,9 @@ module Sidekiq
def client_push(item) # :nodoc:
pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options["pool"] || Sidekiq.redis_pool
# stringify
item.keys.each do |key|
item[key.to_s] = item.delete(key)
end
stringified_item = item.transform_keys(&:to_s)
Sidekiq::Client.new(pool).push(item)
Sidekiq::Client.new(pool).push(stringified_item)
end
end
end