[rubygems/rubygems] Don't use full indexes unnecessarily on legacy Gemfiles

On legacy Gemfiles with multiple remote sources, where all of them
support the compact index API, we were still falling back to full
indexes.

Fixing this also allows to simplifying the code.

https://github.com/rubygems/rubygems/commit/b1357c8e72
This commit is contained in:
David Rodríguez 2023-08-24 23:08:56 +02:00 committed by Hiroshi SHIBATA
parent b5d0374635
commit 023b8ddd22
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
2 changed files with 14 additions and 10 deletions

View File

@ -399,16 +399,11 @@ module Bundler
@remote_specs ||= Index.build do |idx| @remote_specs ||= Index.build do |idx|
index_fetchers = fetchers - api_fetchers index_fetchers = fetchers - api_fetchers
# gather lists from non-api sites if index_fetchers.empty?
fetch_names(index_fetchers, nil, idx, false) fetch_names(api_fetchers, dependency_names, idx, false)
else
# legacy multi-remote sources need special logic to figure out fetch_names(fetchers, nil, idx, false)
# dependency names and that logic can be very costly if one remote end
# uses the dependency API but others don't. So use full indexes
# consistently in that particular case.
allow_api = !multiple_remotes?
fetch_names(api_fetchers, allow_api && dependency_names, idx, false)
end end
end end

View File

@ -35,6 +35,15 @@ RSpec.describe "bundle install with gems on multiple sources" do
expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", :source => "remote1") expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", :source => "remote1")
end end
it "does not use the full index unnecessarily", :bundler => "< 3" do
bundle :install, :artifice => "compact_index", :verbose => true
expect(out).to include("https://gem.repo1/versions")
expect(out).to include("https://gem.repo3/versions")
expect(out).not_to include("https://gem.repo1/quick/Marshal.4.8/")
expect(out).not_to include("https://gem.repo3/quick/Marshal.4.8/")
end
it "fails", :bundler => "3" do it "fails", :bundler => "3" do
bundle :install, :artifice => "compact_index", :raise_on_error => false bundle :install, :artifice => "compact_index", :raise_on_error => false
expect(err).to include("Each source after the first must include a block") expect(err).to include("Each source after the first must include a block")