Skip to content

Commit

Permalink
Merge pull request rubygems#871 from matthewd/defer_fetch
Browse files Browse the repository at this point in the history
Defer API prefetch until it's required
  • Loading branch information
evanphx committed Mar 29, 2014
2 parents b6c756a + 458d1cd commit e7e903b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/rubygems/resolver/api_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def initialize dep_uri = 'https://rubygems.org/api/v1/dependencies'

@data = Hash.new { |h,k| h[k] = [] }
@source = Gem::Source.new @uri

@to_fetch = []
end

##
Expand All @@ -45,6 +47,10 @@ def find_all req

return res unless @remote

if @to_fetch.include?(req.name)
prefetch_now
end

versions(req.name).each do |ver|
if req.dependency.match? req.name, ver[:number]
res << Gem::Resolver::APISpecification.new(self, ver)
Expand All @@ -61,9 +67,13 @@ def find_all req
def prefetch reqs
return unless @remote
names = reqs.map { |r| r.dependency.name }
needed = names - @data.keys
needed = names - @data.keys - @to_fetch

@to_fetch += needed
end

return if needed.empty?
def prefetch_now
needed, @to_fetch = @to_fetch, []

uri = @dep_uri + "?gems=#{needed.sort.join ','}"
str = Gem::RemoteFetcher.fetcher.fetch_path uri
Expand Down

0 comments on commit e7e903b

Please sign in to comment.