Skip to content

Commit

Permalink
Merge pull request #3292 from seanmil/add_facts_performance
Browse files Browse the repository at this point in the history
Improve add_facts performance
  • Loading branch information
donoghuc authored Apr 16, 2024
2 parents f758ac2 + efbca69 commit 00ce3bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bolt/inventory/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def facts

def add_facts(new_facts = {})
validate_fact_names(new_facts)
@facts = Bolt::Util.deep_merge(@facts, new_facts)
Bolt::Util.deep_merge!(@facts, new_facts)
end

def features
Expand Down
11 changes: 11 additions & 0 deletions lib/bolt/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ def deep_merge(hash1, hash2)
hash1.merge(hash2, &recursive_merge)
end

def deep_merge!(hash1, hash2)
recursive_merge = proc do |_key, h1, h2|
if h1.is_a?(Hash) && h2.is_a?(Hash)
h1.merge!(h2, &recursive_merge)
else
h2
end
end
hash1.merge!(hash2, &recursive_merge)
end

# Accepts a Data object and returns a copy with all hash keys
# modified by block. use &:to_s to stringify keys or &:to_sym to symbolize them
def walk_keys(data, &block)
Expand Down

0 comments on commit 00ce3bd

Please sign in to comment.