mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #40171 from vinistock/reduce_allocations_in_cache_methods
Reduce allocations in expanded_version and expanded_key
This commit is contained in:
commit
0e5f9a0a42
1 changed files with 3 additions and 9 deletions
|
@ -617,13 +617,7 @@ module ActiveSupport
|
||||||
# Deletes multiples entries in the cache implementation. Subclasses MAY
|
# Deletes multiples entries in the cache implementation. Subclasses MAY
|
||||||
# implement this method.
|
# implement this method.
|
||||||
def delete_multi_entries(entries, **options)
|
def delete_multi_entries(entries, **options)
|
||||||
entries.inject(0) do |sum, key|
|
entries.count { |key| delete_entry(key, **options) }
|
||||||
if delete_entry(key, **options)
|
|
||||||
sum + 1
|
|
||||||
else
|
|
||||||
sum
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merges the default options with ones specific to a method call.
|
# Merges the default options with ones specific to a method call.
|
||||||
|
@ -687,7 +681,7 @@ module ActiveSupport
|
||||||
expanded_key(key.first)
|
expanded_key(key.first)
|
||||||
end
|
end
|
||||||
when Hash
|
when Hash
|
||||||
key.collect { |k, v| "#{k}=#{v}" }.sort
|
key.collect { |k, v| "#{k}=#{v}" }.sort!
|
||||||
else
|
else
|
||||||
key
|
key
|
||||||
end.to_param
|
end.to_param
|
||||||
|
@ -700,7 +694,7 @@ module ActiveSupport
|
||||||
def expanded_version(key)
|
def expanded_version(key)
|
||||||
case
|
case
|
||||||
when key.respond_to?(:cache_version) then key.cache_version.to_param
|
when key.respond_to?(:cache_version) then key.cache_version.to_param
|
||||||
when key.is_a?(Array) then key.map { |element| expanded_version(element) }.compact.to_param
|
when key.is_a?(Array) then key.map { |element| expanded_version(element) }.tap(&:compact!).to_param
|
||||||
when key.respond_to?(:to_a) then expanded_version(key.to_a)
|
when key.respond_to?(:to_a) then expanded_version(key.to_a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue