From 1867eafe120a97f31c5a8a4976dadf4089b13e1f Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 15 Jun 2017 16:53:02 -0500 Subject: Avoid fetching the full index to get all dependency names --- lib/bundler/source/rubygems.rb | 4 ++-- spec/install/gems/compact_index_spec.rb | 24 ++++++++++++++++++++++ .../artifice/compact_index_extra_api_missing.rb | 16 +++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 spec/support/artifice/compact_index_extra_api_missing.rb diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 8644c05d64..465aec6136 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -249,9 +249,9 @@ module Bundler return unless api_fetchers.any? unmet_dependency_names = unmet_dependency_names.call - Bundler.ui.debug "#{self}: 2x check for #{unmet_dependency_names}" + return if !unmet_dependency_names.nil? && unmet_dependency_names.empty? - return if unmet_dependency_names && unmet_dependency_names.empty? + Bundler.ui.debug "Double checking for #{unmet_dependency_names || "all specs (due to the size of the request)"} in #{self}" fetch_names(api_fetchers, unmet_dependency_names, index, override_dupes) end diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb index 9fc5b1f90a..ad1abe2e89 100644 --- a/spec/install/gems/compact_index_spec.rb +++ b/spec/install/gems/compact_index_spec.rb @@ -363,6 +363,30 @@ The checksum of /versions does not match the checksum provided by the server! So expect(the_bundle).to include_gems "back_deps 1.0" end + it "does not fetch every spec if the index of gems is large when doing back deps & everything is the compact index" do + build_repo4 do + build_gem "back_deps" do |s| + s.add_dependency "foo" + end + build_gem "missing" + # need to hit the limit + 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| + build_gem "gem#{i}" + end + + FileUtils.rm_rf Dir[gem_repo4("gems/foo-*.gem")] + end + + install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing" + source "#{source_uri}" + source "#{source_uri}/extra" do + gem "back_deps" + end + G + + expect(the_bundle).to include_gem "back_deps 1.0" + end + it "uses the endpoint if all sources support it" do gemfile <<-G source "#{source_uri}" diff --git a/spec/support/artifice/compact_index_extra_api_missing.rb b/spec/support/artifice/compact_index_extra_api_missing.rb new file mode 100644 index 0000000000..d11793fc2b --- /dev/null +++ b/spec/support/artifice/compact_index_extra_api_missing.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +require File.expand_path("../compact_index_extra_api", __FILE__) + +Artifice.deactivate + +class CompactIndexExtraAPIMissing < CompactIndexExtraApi + get "/extra/fetch/actual/gem/:id" do + if params[:id] == "missing-1.0.gemspec.rz" + halt 404 + else + File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + end + end +end + +Artifice.activate_with(CompactIndexExtraAPIMissing) -- cgit v1.2.1