mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00

Every time a gem is not found in the Compact Index API, RubyGems will
fallback to the full index, which is very slow. This is unnecessary
because both indexes should be providing the same gems, so if a gem
can't be found in the Compact Index API, it won't be found in the full
index.
We _do_ want a fallback to the full index, whenever the Compact Index
API is not implemented. To detect that, we check that the API responds
to the "/versions" endpoint, just like Bundler does.
Before:
```
$ time gem install fooasdsfafs
ERROR: Could not find a valid gem 'fooasdsfafs' (>= 0) in any repository
gem 20,77s user 0,59s system 96% cpu 22,017 total
```
After:
```
$ time gem install fooasdsfafs
ERROR: Could not find a valid gem 'fooasdsfafs' (>= 0) in any repository
gem 5,02s user 0,09s system 91% cpu 5,568 total
```
c0d6b9eea7
51 lines
989 B
Ruby
51 lines
989 B
Ruby
# frozen_string_literal: true
|
|
|
|
##
|
|
# The BestSet chooses the best available method to query a remote index.
|
|
#
|
|
# It combines IndexSet and APISet
|
|
|
|
class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet
|
|
##
|
|
# Creates a BestSet for the given +sources+ or Gem::sources if none are
|
|
# specified. +sources+ must be a Gem::SourceList.
|
|
|
|
def initialize(sources = Gem.sources)
|
|
super()
|
|
|
|
@sources = sources
|
|
end
|
|
|
|
##
|
|
# Picks which sets to use for the configured sources.
|
|
|
|
def pick_sets # :nodoc:
|
|
@sources.each_source do |source|
|
|
@sets << source.dependency_resolver_set
|
|
end
|
|
end
|
|
|
|
def find_all(req) # :nodoc:
|
|
pick_sets if @remote && @sets.empty?
|
|
|
|
super
|
|
rescue Gem::RemoteFetcher::FetchError
|
|
[]
|
|
end
|
|
|
|
def prefetch(reqs) # :nodoc:
|
|
pick_sets if @remote && @sets.empty?
|
|
|
|
super
|
|
end
|
|
|
|
def pretty_print(q) # :nodoc:
|
|
q.group 2, "[BestSet", "]" do
|
|
q.breakable
|
|
q.text "sets:"
|
|
|
|
q.breakable
|
|
q.pp @sets
|
|
end
|
|
end
|
|
end
|