diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-04-23 13:22:12 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-04-23 13:22:12 -0700 |
commit | d37e60aa20018776cc8eb766d3590c205f6f984a (patch) | |
tree | b70affb8a61317d7aaebe4320e9f235a956e7b69 | |
parent | e9cedd0d497812a5f481ec55c9096bd8ee2d2aae (diff) | |
download | chef-d37e60aa20018776cc8eb766d3590c205f6f984a.tar.gz |
Revert "fix Chef-14 chef_fs/chef-zero perf regression"
This reverts commit 79c8782bbc9ca07898bda6ff9a3a7cdcc39bcdcf.
-rw-r--r-- | lib/chef/chef_fs/chef_fs_data_store.rb | 46 | ||||
-rw-r--r-- | spec/integration/knife/chef_fs_data_store_spec.rb | 2 |
2 files changed, 20 insertions, 28 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index e44c2cb8b8..cdb793f808 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright 2012-2018, Chef Software Inc. +# Copyright:: Copyright 2012-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -307,14 +307,25 @@ class Chef # GET /cookbooks/NAME/VERSION or /cookbook_artifacts/NAME/IDENTIFIER elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 3 - with_cookbook_manifest(path) do |manifest, entry| + with_entry([path[0]]) do |entry| cookbook_type = path[0] + cookbook_entry = entry.children.select do |child| + child.chef_object.full_name == "#{path[1]}-#{path[2]}" || + (child.chef_object.name.to_s == path[1] && child.chef_object.identifier == path[2]) + end[0] + raise ChefZero::DataStore::DataNotFoundError.new(path) if cookbook_entry.nil? + result = nil + begin + result = Chef::CookbookManifest.new(cookbook_entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash + rescue Chef::ChefFS::FileSystem::NotFoundError => e + raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) + end - manifest.each_pair do |key, value| + result.each_pair do |key, value| if value.is_a?(Array) value.each do |file| if file.is_a?(Hash) && file.has_key?("checksum") - relative = ["file_store", "repo", cookbook_type, entry.name ] + relative = ["file_store", "repo", cookbook_type, cookbook_entry.name ] relative += file[:path].split("/") file["url"] = ChefZero::RestBase.build_uri(request.base_uri, relative) end @@ -323,8 +334,8 @@ class Chef end if cookbook_type == "cookbook_artifacts" - manifest["metadata"] = manifest["metadata"].to_hash - manifest["metadata"].delete_if do |key, value| + result["metadata"] = result["metadata"].to_hash + result["metadata"].delete_if do |key, value| value == [] || (value == {} && !%w{dependencies attributes recipes}.include?(key)) || (value == "" && %w{source_url issues_url}.include?(key)) || @@ -332,8 +343,9 @@ class Chef end end - Chef::JSONCompat.to_json_pretty(manifest) + Chef::JSONCompat.to_json_pretty(result) end + else with_entry(path) do |entry| begin @@ -756,26 +768,6 @@ class Chef path.length == 1 && BASE_DIRNAMES.include?(path[0]) end - def with_cookbook_manifest(path) - cookbook_type = path[0] - begin - # this is fast and equivalent to with_entry() that also returns the cb manifest - entry = Chef::ChefFS::FileSystem.resolve_path(chef_fs, to_chef_fs_path(path)) - yield Chef::CookbookManifest.new(entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash, entry - rescue Chef::ChefFS::FileSystem::NotFoundError, ChefZero::DataStore::DataNotFoundError => e - # this is very slow and we walk through all the cookbook versions to find ones that have the correct name in the metadata - dir = Chef::ChefFS::FileSystem.resolve_path(chef_fs, to_chef_fs_path([path[0]])) - entry = dir.children.select do |child| - child.chef_object.full_name == "#{path[1]}-#{path[2]}" || - (child.chef_object.name.to_s == path[1] && child.chef_object.identifier == path[2]) - end[0] - raise ChefZero::DataStore::DataNotFoundError.new(path) if entry.nil? - yield Chef::CookbookManifest.new(entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash, entry - end - rescue Chef::ChefFS::FileSystem::NotFoundError => e - raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) - end - def with_entry(path) yield Chef::ChefFS::FileSystem.resolve_path(chef_fs, to_chef_fs_path(path)) rescue Chef::ChefFS::FileSystem::NotFoundError => e diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb index d50968f327..ff674082b7 100644 --- a/spec/integration/knife/chef_fs_data_store_spec.rb +++ b/spec/integration/knife/chef_fs_data_store_spec.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright 2013-2018, Chef Software Inc. +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); |