Skip to content
Snippets Groups Projects
Unverified Commit c038933d authored by Tobias Bieniek's avatar Tobias Bieniek Committed by GitHub
Browse files

crates: Use `?include=` to reduce crates.io backend load (#9081)

By default the `/crates/:crate_name` API endpoint returns the categories and keywords related to the crates. Unfortunately this causes two additional database queries on the crates.io backend.

This commit change the request URL to use `?include=` to only include the additional metadata that is needed for the requested badges.
parent 148b51d5
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ class BaseCratesService extends BaseJsonService { ...@@ -44,7 +44,7 @@ class BaseCratesService extends BaseJsonService {
async fetch({ crate, version }) { async fetch({ crate, version }) {
const url = version const url = version
? `https://crates.io/api/v1/crates/${crate}/${version}` ? `https://crates.io/api/v1/crates/${crate}/${version}`
: `https://crates.io/api/v1/crates/${crate}` : `https://crates.io/api/v1/crates/${crate}?include=versions,downloads`
return this._requestJson({ schema, url }) return this._requestJson({ schema, url })
} }
} }
......
...@@ -34,7 +34,7 @@ t.create('recent downloads (null)') ...@@ -34,7 +34,7 @@ t.create('recent downloads (null)')
.get('/dr/libc.json') .get('/dr/libc.json')
.intercept(nock => .intercept(nock =>
nock('https://crates.io') nock('https://crates.io')
.get('/api/v1/crates/libc') .get('/api/v1/crates/libc?include=versions,downloads')
.reply(200, { .reply(200, {
crate: { crate: {
downloads: 42, downloads: 42,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment