From fe1e1c784ea762fd4b7f8d441b8a2508460646ab Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Wed, 12 Nov 2025 19:19:05 +0100 Subject: [ruby/rubygems] Adjust the API_REQUEST_LIMIT: - ### Problem This limit is used when Bundler fallback to getting a dependency list from a server `/dependencies?gem=` endpoint. Bundler uses this API endpoint fallback when a server doesn't expose the compact index API. This is not used for Rubygems.org, only private servers. This limit is then divided by the number of dependency to get and the result is the number of request we'll be doing. The bottleneck on the client is the network roundtrip. On the server, getting the info of 50 or 100 gems is a bit more expensive but this operation is heavily cached. This is an example of Rubygems.org implementation at the time the dependencies API wasn't deprecated https://github.com/rubygems/rubygems.org/blob/5a3a3ec02acc3a4e3aba077953a393ad20a06842/app/models/gem_dependent.rb#L15 ### Context This limit used to be 100 a while ago but got changed to 50 in https://github.com/ruby/rubygems/commit/e745f8dc901dd419e7dc8aede3e8d49569fc7b1e I don't know why. ### Solution 50 gems to query seems arbitrary low. By doubling this number, we make twice as less API requests which ultimately can shove up to two seconds on application relying on a large number of gems. https://github.com/ruby/rubygems/commit/831894043c --- lib/bundler/source/rubygems.rb | 2 +- spec/bundler/bundler/fetcher/dependency_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 2631c860a0..e420d8395f 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -8,7 +8,7 @@ module Bundler autoload :Remote, File.expand_path("rubygems/remote", __dir__) # Ask for X gems per API request - API_REQUEST_SIZE = 50 + API_REQUEST_SIZE = 100 attr_accessor :remotes diff --git a/spec/bundler/bundler/fetcher/dependency_spec.rb b/spec/bundler/bundler/fetcher/dependency_spec.rb index c420b7c07f..61e32acfd9 100644 --- a/spec/bundler/bundler/fetcher/dependency_spec.rb +++ b/spec/bundler/bundler/fetcher/dependency_spec.rb @@ -212,7 +212,7 @@ RSpec.describe Bundler::Fetcher::Dependency do let(:dep_api_uri) { double(:dep_api_uri) } let(:unmarshalled_gems) { double(:unmarshalled_gems) } let(:fetch_response) { double(:fetch_response, body: double(:body)) } - let(:rubygems_limit) { 50 } + let(:rubygems_limit) { 100 } before { allow(subject).to receive(:dependency_api_uri).with(gem_names).and_return(dep_api_uri) } -- cgit v1.2.3