diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-06-06 12:58:26 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-06-11 08:05:36 +1000 |
| commit | 607b01e82ea294068fdd554e59bc8e5fe3f9761a (patch) | |
| tree | 67065307f00a4bb1082cbb5aeb752d4cebf3e579 /lib | |
| parent | 06b919ddb7d635abfe7855336e0e5af67675b44e (diff) | |
| download | puppet-607b01e82ea294068fdd554e59bc8e5fe3f9761a.tar.gz puppet-607b01e82ea294068fdd554e59bc8e5fe3f9761a.tar.xz puppet-607b01e82ea294068fdd554e59bc8e5fe3f9761a.zip | |
Fix #2246 - take2: make sure we run the rails tag query only when needed
Adding the tags to the rails collect query can reduce performance
because there are 2 more tables to join with.
So we make sure to include tags in the query only when it is
necessary.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/parser/collector.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index 5f11a6cea..a7f81b4e7 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -102,13 +102,20 @@ class Puppet::Parser::Collector raise Puppet::DevError, "Cannot collect resources for a nil host" unless @scope.host host = Puppet::Rails::Host.find_by_name(@scope.host) - query = {:include => {:param_values => :param_name, :puppet_tags => :resource_tags}} + query = {:include => {:param_values => :param_name}} search = "(exported=? AND restype=?)" values = [true, @type] search += " AND (%s)" % @equery if @equery + # this is a small performance optimisation + # the tag mechanism involves 3 more joins, which are + # needed only if we query on tags. + if search =~ /puppet_tags/ + query[:include][:puppet_tags] = :resource_tags + end + # We're going to collect objects from rails, but we don't want any # objects from this host. search = ("host_id != ? AND %s" % search) and values.unshift(host.id) if host |
