Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup duplicate rule detection #1068

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/puppet/provider/firewall/iptables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ def exists?
end

def duplicate_rule?(rule)
rules = self.class.instances
system_rule_count = Hash.new(0)
rules.each { |r| system_rule_count[r.name] += 1 }
duplicate_rules = rules.select { |r| system_rule_count[r.name] > 1 }
duplicate_rules.select { |r| r.name == rule }.any?
self.class.instances.each_with_object({ count: 0 }) do |r, obj|
obj[:count] += 1 if r.name == rule
return true if obj[:count] > 1
end
false
end

# Flush the property hash once done.
Expand Down