Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid spurious downloads during dependency management #1124

Merged
merged 1 commit into from
Sep 22, 2016

Conversation

stevendanna
Copy link
Contributor

Before, a URL based source might be downloaded multiple times during the
dependency fetching and lockfile creation. This commit tries to avoid
this by:

  1. Memoizing data about the archive to avoid re-fetching the archive

  2. Adding a CachedFetcher wrapper around the fetcher class to help
    ensure that callers always consult the cache before fetching.

Signed-off-by: Steven Danna steve@chef.io

opts[:backend] = @backend
if !@dependencies.nil?
opts[:dependencies] = Inspec::DependencySet.from_array(@dependencies, @cwd, @cache, @backend)
end
@profile ||= Inspec::Profile.for_target(opts, opts)
@profile = Inspec::Profile.for_fetcher(fetcher, opts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this for a while, since it now deviated from our CLI code. We are using a separate mechanism for inspec json now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rephrase this comment? I'm don't understand what you are trying to indicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: We are going to leave for_fetcher() but change it so that for_target calls for_fetcher so that it is hard to introduce drifting behavior between the two, this will require the fetcher to expose the original target via an attr_accessor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done now.

@@ -72,9 +35,14 @@ def self.for_path(path, opts)
new(reader, opts)
end

def self.for_fetcher(fetcher, opts)
path, writable = fetcher.fetch
for_path(path, opts.merge(target: fetcher.target, writable: writable))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to attach the fetcher to the profile and just read the target then from the fetcher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris-rock My plan was to do soemthing like that in a follow up PR since I think that is ultimately what we need to do to remove the Requirement class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, lets go for that approach

Before, a URL based source might be downloaded multiple times during the
dependency fetching and lockfile creation. This commit tries to avoid
this by:

1) Memoizing data about the archive to avoid re-fetching the archive

2) Adding a CachedFetcher wrapper around the fetcher class to help
ensure that callers always consult the cache before fetching.

Signed-off-by: Steven Danna <steve@chef.io>
@chris-rock
Copy link
Contributor

Thanks @stevendanna for this improvement.

@chris-rock chris-rock merged commit 543db25 into master Sep 22, 2016
@chris-rock chris-rock deleted the ssd/stahp-using-my-bandwidth branch September 22, 2016 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants