From ec7ea27e356dc159b37cc2a09b6f14841e796ab2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 22 Mar 2010 16:39:21 -0700 Subject: Refactoring event queueing for performance This does some normalization so we're not doing duplicate queries for large event collections. Signed-off-by: Luke Kanies --- lib/puppet/transaction/event_manager.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb index f74927b3c..24e577803 100644 --- a/lib/puppet/transaction/event_manager.rb +++ b/lib/puppet/transaction/event_manager.rb @@ -33,7 +33,17 @@ class Puppet::Transaction::EventManager def queue_events(resource, events) @events += events - events.each do |event| + # Do some basic normalization so we're not doing so many + # graph queries for large sets of events. + events.inject({}) do |collection, event| + collection[event.name] ||= [] + collection[event.name] << event + collection + end.collect do |name, list| + # It doesn't matter which event we use - they all have the same source + # and name here. + event = list[0] + # Collect the targets of any subscriptions to those events. We pass # the parent resource in so it will override the source in the events, # since eval_generated children can't have direct relationships. @@ -41,7 +51,9 @@ class Puppet::Transaction::EventManager next unless method = edge.callback next unless edge.target.respond_to?(method) - queue_event_for_resource(resource, edge.target, method, event) + list.each do |e| + queue_event_for_resource(resource, edge.target, method, e) + end end if resource.self_refresh? and ! resource.deleting? -- cgit