Skip to content

Commit 5228d2f

Browse files
authored
GET /crates/:crate_id/:version/download: Remove log_metadata variable (#5865)
This may have been necessary while `&mut req` was needed for the `req.add_custom_metadata()` call, but since that is no longer the case, we can simplify the code here.
1 parent 196cefb commit 5228d2f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/controllers/version/downloads.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ pub async fn download(req: ConduitRequest) -> AppResult<Response> {
2020
let mut crate_name = req.param("crate_id").unwrap().to_string();
2121
let version = req.param("version").unwrap();
2222

23-
let mut log_metadata = None;
24-
2523
let cache_key = (crate_name.to_string(), version.to_string());
2624
if let Some(version_id) = app.version_id_cacher.get(&cache_key) {
2725
app.instance_metrics.version_id_cache_hits.inc();
@@ -67,7 +65,7 @@ pub async fn download(req: ConduitRequest) -> AppResult<Response> {
6765
app.instance_metrics
6866
.downloads_non_canonical_crate_name_total
6967
.inc();
70-
log_metadata = Some(("bot", "dl"));
68+
req.add_custom_metadata("bot", "dl");
7169
crate_name = canonical_crate_name;
7270
} else {
7371
// The version_id is only cached if the provided crate name was canonical.
@@ -99,16 +97,12 @@ pub async fn download(req: ConduitRequest) -> AppResult<Response> {
9997
app.instance_metrics
10098
.downloads_unconditional_redirects_total
10199
.inc();
102-
log_metadata = Some(("unconditional_redirect", "true"));
100+
101+
req.add_custom_metadata("unconditional_redirect", "true");
103102
}
104103
};
105104

106105
let redirect_url = app.config.uploader().crate_location(&crate_name, version);
107-
108-
if let Some((key, value)) = log_metadata {
109-
req.add_custom_metadata(key, value);
110-
}
111-
112106
if req.wants_json() {
113107
Ok(Json(json!({ "url": redirect_url })).into_response())
114108
} else {

0 commit comments

Comments
 (0)