Skip to content

Commit 6e0f5d6

Browse files
sdelanoSeth Falcon
authored andcommitted
don't load node twice when fetching it's cookbooks
1 parent f8b9332 commit 6e0f5d6

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

chef-server-api/app/controllers/nodes.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,15 @@ def cookbooks
8686
raise NotFound, "Cannot load node #{params[:id]}"
8787
end
8888

89-
display(load_all_files(params[:id]))
89+
display(load_all_files)
9090
end
9191

9292
private
9393

94-
def load_all_files(node_name)
95-
all_cookbooks = Chef::CookbookVersion.cdb_list(true).inject({}) do |res, cookbook|
96-
version = Gem::Version.new cookbook.version
97-
newest_version = res.has_key?(cookbook.name) ? version > Gem::Version.new(res[cookbook.name].version) : true
98-
res[cookbook.name] = cookbook if newest_version
99-
res
100-
end
94+
def load_all_files
95+
all_cookbooks = Chef::CookbookVersion.cdb_list(true).inject({}) {|hsh,record| hsh[record.name] = record ; hsh}
10196

102-
included_cookbooks = cookbooks_for_node(node_name, all_cookbooks)
97+
included_cookbooks = cookbooks_for_node(all_cookbooks)
10398
nodes_cookbooks = Hash.new
10499
included_cookbooks.each do |cookbook_name, cookbook|
105100
next unless cookbook
@@ -111,12 +106,9 @@ def load_all_files(node_name)
111106
end
112107

113108
# returns name -> CookbookVersion for all cookbooks included on the given node.
114-
def cookbooks_for_node(node_name, all_cookbooks)
115-
# get node's explicit dependencies
116-
node = Chef::Node.cdb_load(node_name)
117-
109+
def cookbooks_for_node(all_cookbooks)
118110
# expand returns a RunListExpansion which contains recipes, default and override attrs [cb]
119-
recipes = node.run_list.expand('couchdb').recipes
111+
recipes = @node.run_list.expand('couchdb').recipes
120112

121113
# walk run list and accumulate included dependencies
122114
recipes.inject({}) do |included_cookbooks, recipe|

0 commit comments

Comments
 (0)