summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-14 17:41:42 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-06-14 17:41:42 +0000
commit45f76c5d0cb6473faf7dca656b90e299799edf94 (patch)
treec3585ae047c1b46fc45a1011549daa546b5290e7 /lib/puppet
parente32a1bd40e6d706b4e0c5316bf32aec52133f309 (diff)
downloadpuppet-45f76c5d0cb6473faf7dca656b90e299799edf94.tar.gz
puppet-45f76c5d0cb6473faf7dca656b90e299799edf94.tar.xz
puppet-45f76c5d0cb6473faf7dca656b90e299799edf94.zip
Significantly optimizing the database queries -- I am getting about 40% better times now. See http://www.madstop.com/optimizing_the_activerecord_integration.html.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2585 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/resource.rb2
-rw-r--r--lib/puppet/rails/database/schema.rb1
-rw-r--r--lib/puppet/rails/host.rb8
-rw-r--r--lib/puppet/rails/resource.rb12
4 files changed, 13 insertions, 10 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 4147d6327..25c9ab707 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -190,7 +190,7 @@ class Puppet::Parser::Resource
hash
end
- db_resource.ar_hash_merge(db_resource.get_params_hash(), updated_params,
+ db_resource.ar_hash_merge(db_resource.get_params_hash(db_resource.param_values), updated_params,
:create => Proc.new { |name, parameter|
parameter.to_rails(db_resource)
}, :delete => Proc.new { |values|
diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb
index 0bc4bc5cb..81a1cdbc3 100644
--- a/lib/puppet/rails/database/schema.rb
+++ b/lib/puppet/rails/database/schema.rb
@@ -42,7 +42,6 @@ class Puppet::Rails::Schema
t.column :updated_at, :datetime
end
add_index :puppet_tags, :id, :integer => true
- add_index :puppet_tags, :name
create_table :hosts do |t|
t.column :name, :string, :null => false
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index 58808b178..cd60a2b4b 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -123,10 +123,12 @@ class Puppet::Rails::Host < ActiveRecord::Base
def setresources(list)
existing = nil
seconds = Benchmark.realtime {
- #existing = resources.find(:all)
-
- existing = resources.find(:all, :include => [{:param_values => :param_name, :resource_tags => :puppet_tag}, :source_file]).inject({}) do | hash, resource |
+ # Preload the parameters with the resource query, but not the tags, since doing so makes the query take about 10x longer.
+ # I've left the other queries in so that it's straightforward to switch between them for testing, if we so desire.
+ #existing = resources.find(:all, :include => [{:param_values => :param_name, :resource_tags => :puppet_tag}, :source_file]).inject({}) do | hash, resource |
+ #existing = resources.find(:all, :include => [{:resource_tags => :puppet_tag}, :source_file]).inject({}) do | hash, resource |
+ existing = resources.find(:all, :include => [{:param_values => :param_name}, :source_file]).inject({}) do | hash, resource |
hash[resource.ref] = resource
hash
end
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index 0287a5a76..2f58681ab 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -16,7 +16,7 @@ class Puppet::Rails::Resource < ActiveRecord::Base
belongs_to :host
def add_resource_tag(tag)
- pt = Puppet::Rails::PuppetTag.find_or_create_by_name(tag)
+ pt = Puppet::Rails::PuppetTag.find_or_create_by_name(tag, :include => :puppet_tag)
resource_tags.create(:puppet_tag => pt)
end
@@ -33,16 +33,18 @@ class Puppet::Rails::Resource < ActiveRecord::Base
end
# returns a hash of param_names.name => [param_values]
- def get_params_hash
- return param_values.inject({}) do | hash, value |
+ def get_params_hash(values = nil)
+ values ||= param_values.find(:all, :include => :param_name)
+ return values.inject({}) do | hash, value |
hash[value.param_name.name] ||= []
hash[value.param_name.name] << value
hash
end
end
- def get_tag_hash
- return resource_tags.inject({}) do |hash, tag|
+ def get_tag_hash(tags = nil)
+ tags ||= resource_tags.find(:all, :include => :puppet_tag)
+ return tags.inject({}) do |hash, tag|
hash[tag.puppet_tag.name] = tag.puppet_tag.name
hash
end