summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2010-07-01 16:21:05 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-02 12:31:53 -0700
commitea55e8328fcb8c33d7b20f91cc9f21da31ba935d (patch)
treecb5f6cbc3a91b4ddecec61720e580f672e2e20fe
parent7c7f6da17c4f088175e7d616e390b5c7e1e5e65f (diff)
downloadpuppet-ea55e8328fcb8c33d7b20f91cc9f21da31ba935d.tar.gz
puppet-ea55e8328fcb8c33d7b20f91cc9f21da31ba935d.tar.xz
puppet-ea55e8328fcb8c33d7b20f91cc9f21da31ba935d.zip
Maint: Improve the speed of setting settings.
Our settings were slow because I was querying Application objects for their run_mode repetitively
-rw-r--r--lib/puppet/util/settings.rb31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index d1e1448cb..e1f7c3578 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -474,6 +474,24 @@ class Puppet::Util::Settings
return @service_user_available = user.exists?
end
+ def legacy_to_mode(type, param)
+ if not defined? @app_names then
+ require 'puppet/util/command_line'
+ command_line = Puppet::Util::CommandLine.new
+ @app_names = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair|
+ app, legacy = pair
+ command_line.require_application app
+ hash[legacy.to_sym] = Puppet::Application.find(app).run_mode.name
+ hash
+ end
+ end
+ if new_type = @app_names[type]
+ Puppet.warning "You have configuration parameter $#{param} specified in [#{type}], which is a deprecated section. I'm assuming you meant [#{new_type}]"
+ return new_type
+ end
+ return type
+ end
+
def set_value(param, value, type, options = {})
param = param.to_sym
unless setting = @config[param]
@@ -494,18 +512,7 @@ class Puppet::Util::Settings
raise ArgumentError,
"You're attempting to set configuration parameter $#{param}, which is read-only."
end
- require 'puppet/util/command_line'
- command_line = Puppet::Util::CommandLine.new
- legacy_to_mode = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair|
- app, legacy = pair
- command_line.require_application app
- hash[legacy.to_sym] = Puppet::Application.find(app).run_mode.name
- hash
- end
- if new_type = legacy_to_mode[type]
- Puppet.warning "You have configuration parameter $#{param} specified in [#{type}], which is a deprecated section. I'm assuming you meant [#{new_type}]"
- type = new_type
- end
+ type = legacy_to_mode(type, param)
@sync.synchronize do # yay, thread-safe
@values[type][param] = value
@cache.clear