diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-22 04:56:05 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-22 04:56:05 +0000 |
| commit | 5bd0e8c6035e5d175c6c609813e844ae3a77a055 (patch) | |
| tree | 22f04c756f0a3ed1360d4a901c379b7be83f7129 /lib/puppet/parser | |
| parent | 4c357d84960bc3cbaf26db8d9a94eccbf95f9a34 (diff) | |
Rails is now significantly faster. I refactored all of the queries; they are mostly reduced to three queries, each of which is relatively fast, although there are still a ton of file- and tag-related queries that I cannot find the source of. Note that this speedup requires indexes, which will only get added if you start puppetmasterd with --dbmigrate (although you cannot always start with that, as there is an error in the init code). I expect that the indexes will not help unless you forcibly reindex your database, but after that you should see significant speed improvements.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2344 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/resource.rb | 55 | ||||
| -rw-r--r-- | lib/puppet/parser/resource/param.rb | 31 |
2 files changed, 62 insertions, 24 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index bdace28cd..8ef382204 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -256,40 +256,59 @@ class Puppet::Parser::Resource end # Turn our parser resource into a Rails resource. - def to_rails(host) + def to_rails(host, resource = nil) args = {} - %w{type title tags file line exported}.each do |param| + [:type, :title, :tags, :file, :line, :exported].each do |param| + # 'type' isn't a valid column name, so we have to use something else. + if param == :type + to = :restype + else + to = param + end if value = self.send(param) - args[param] = value + args[to] = value end end - # 'type' isn't a valid column name, so we have to use something else. - args = symbolize_options(args) - args[:restype] = args[:type] - args.delete(:type) - - # Let's see if the object exists - if obj = host.resources.find_by_restype_and_title(self.type, self.title) + # If we were passed an object, just make sure all of the attributes are correct. + if resource # We exist args.each do |param, value| - obj[param] = value + unless resource[param] == value + resource[param] = value + end end else # Else create it anew - obj = host.resources.build(args) + resource = host.resources.build(args) end - if l = self.line - obj.line = l + # Either way, now add our parameters + newparams = @params.dup + remove = [] + resource.param_names.each do |pn| + name = pn.name.intern + if param = newparams[name] + # Mark that we found this in the db + newparams.delete(name) + param.to_rails(resource, pn) + else + remove << pn + end end - # Either way, now add our parameters - obj.collection_merge(:param_names, @params) do |name, param| - param.to_rails(obj) + newparams.each do |name, param| + param.to_rails(resource) end - return obj + remove.each do |param| + resource.param_names.delete(param) + end + #obj.collection_merge(:param_names, @params) do |name, param| + # param.to_rails(obj) + #end + + return resource end def to_s diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index 1f7a66aae..56a50de1c 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -16,10 +16,12 @@ class Puppet::Parser::Resource::Param end # Store this parameter in a Rails db. - def to_rails(res) + def to_rails(res, pn = nil) values = value.is_a?(Array) ? value : [value] - unless pn = res.param_names.find_by_name(self.name.to_s) + values = values.collect { |v| v.to_s } + + unless pn # We're creating it anew. pn = res.param_names.build(:name => self.name.to_s) end @@ -30,13 +32,30 @@ class Puppet::Parser::Resource::Param pn.line = Integer(l) end - pn.collection_merge(:param_values, values) do |value| - unless pv = pn.param_values.find_by_value(value) - pv = pn.param_values.build(:value => value) + oldvals = [] + + if pv = pn.param_values + newvals = pv.each do |val| + oldvals << val.value + end + end + + if oldvals != values + #pn.param_values = values.collect { |v| pn.param_values.build(:value => v.to_s) } + objects = values.collect do |v| + pn.param_values.build(:value => v.to_s) end - pv + pn.param_values = objects + #pn.save end +# pn.collection_merge(:param_values, values) do |value| +# unless pv = pn.param_values.find_by_value(value) +# pv = pn.param_values.build(:value => value) +# end +# pv +# end + return pn end |
