Skip to content

Commit 1a3bace

Browse files
committed
Add a new Bundler config to control how many specs are fetched:
- ### Problem In #9071, I increased the API_REQUEST_SIZE constants to fetch 100 specifications at once instead of 50. Worth to remember that this codepath is exclusively used for servers that don't implement the compact index API and where Bundler has to fallback on the `/v1/dependencies` endpoint. Fetching 100 gems at once seems not supported by some gem servers. See #9345 ### Solution I'd like to provide a new Bundler configuration `BUNDLE_API_REQUEST_SIZE` to let users of those servers control how many dependencies should be fetched at once. ### Alternatives The other alternative is to revert #9071 and always fetch 50 specs. I tried the number 100 on a single rubygem registry (cloudsmith), and I don't have data point to know whether this value is supported by most registries.
1 parent 213ad60 commit 1a3bace

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

bundler/lib/bundler/fetcher/dependency.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def dependency_specs(gem_names)
5050

5151
def unmarshalled_dep_gems(gem_names)
5252
gem_list = []
53-
gem_names.each_slice(Source::Rubygems::API_REQUEST_SIZE) do |names|
53+
gem_names.each_slice(api_request_size) do |names|
5454
marshalled_deps = downloader.fetch(dependency_api_uri(names)).body
5555
gem_list.concat(Bundler.safe_load_marshal(marshalled_deps))
5656
end
@@ -74,6 +74,12 @@ def dependency_api_uri(gem_names = [])
7474
uri.query = "gems=#{CGI.escape(gem_names.sort.join(","))}" if gem_names.any?
7575
uri
7676
end
77+
78+
private
79+
80+
def api_request_size
81+
Bundler.settings[:api_request_size]&.to_i || Source::Rubygems::API_REQUEST_SIZE
82+
end
7783
end
7884
end
7985
end

bundler/lib/bundler/man/bundle-config.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" generated with Ronn-NG/v0.10.1
22
.\" http://github.com/apjanke/ronn-ng/tree/0.10.1
3-
.TH "BUNDLE\-CONFIG" "1" "February 2026" ""
3+
.TH "BUNDLE\-CONFIG" "1" "March 2026" ""
44
.SH "NAME"
55
\fBbundle\-config\fR \- Set bundler configuration options
66
.SH "SYNOPSIS"
@@ -70,6 +70,9 @@ Any periods in the configuration keys must be replaced with two underscores when
7070
.SH "LIST OF AVAILABLE KEYS"
7171
The following is a list of all configuration keys and their purpose\. You can learn more about their operation in bundle install(1) \fIbundle\-install\.1\.html\fR\.
7272
.TP
73+
\fBapi_request_size\fR (\fBBUNDLE_API_REQUEST_SIZE\fR)
74+
Configure how many dependencies to fetch when resolving the specifications\. This configuration is only used when fetchig specifications from RubyGems servers that didn't implement the Compact Index API\. Defaults to 100\.
75+
.TP
7376
\fBauto_install\fR (\fBBUNDLE_AUTO_INSTALL\fR)
7477
Automatically run \fBbundle install\fR when gems are missing\.
7578
.TP

bundler/lib/bundler/man/bundle-config.1.ronn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ the environment variable `BUNDLE_LOCAL__RACK`.
106106
The following is a list of all configuration keys and their purpose. You can
107107
learn more about their operation in [bundle install(1)](bundle-install.1.html).
108108

109+
* `api_request_size` (`BUNDLE_API_REQUEST_SIZE`):
110+
Configure how many dependencies to fetch when resolving the specifications.
111+
This configuration is only used when fetchig specifications from RubyGems
112+
servers that didn't implement the Compact Index API.
113+
Defaults to 100.
109114
* `auto_install` (`BUNDLE_AUTO_INSTALL`):
110115
Automatically run `bundle install` when gems are missing.
111116
* `bin` (`BUNDLE_BIN`):

bundler/spec/bundler/fetcher/dependency_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@
222222
expect(Bundler).to receive(:safe_load_marshal).with(fetch_response.body).and_return([unmarshalled_gems])
223223
expect(subject.unmarshalled_dep_gems(gem_names)).to eq([unmarshalled_gems])
224224
end
225+
226+
it "should fetch as many dependencies as specified" do
227+
allow(subject).to receive(:dependency_api_uri).with([%w[foo bar]]).and_return(dep_api_uri)
228+
allow(subject).to receive(:dependency_api_uri).with([%w[bundler rubocop]]).and_return(dep_api_uri)
229+
230+
expect(downloader).to receive(:fetch).twice.with(dep_api_uri).and_return(fetch_response)
231+
expect(Bundler).to receive(:safe_load_marshal).twice.with(fetch_response.body).and_return([unmarshalled_gems])
232+
233+
Bundler.settings.temporary(api_request_size: 1) do
234+
expect(subject.unmarshalled_dep_gems(gem_names)).to eq([unmarshalled_gems, unmarshalled_gems])
235+
end
236+
end
225237
end
226238

227239
describe "#get_formatted_specs_and_deps" do

0 commit comments

Comments
 (0)