Skip to content

Commit ef234a4

Browse files
committed
publish: Use sync_to_git/sparse_index() jobs if FEATURE_INDEX_SYNC env var is set
1 parent ae1535f commit ef234a4

7 files changed

+21
-11
lines changed

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct Server {
4747
pub version_id_cache_ttl: Duration,
4848
pub cdn_user_agent: String,
4949
pub balance_capacity: BalanceCapacityConfig,
50+
pub feature_index_sync: bool,
5051
}
5152

5253
impl Default for Server {
@@ -151,6 +152,7 @@ impl Default for Server {
151152
cdn_user_agent: dotenv::var("WEB_CDN_USER_AGENT")
152153
.unwrap_or_else(|_| "Amazon CloudFront".into()),
153154
balance_capacity: BalanceCapacityConfig::from_environment(),
155+
feature_index_sync: dotenv::var("FEATURE_INDEX_SYNC").is_ok(),
154156
}
155157
}
156158
}

src/controllers/krate/publish.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Functionality related to publishing a new crate or version of a crate.
22
33
use crate::auth::AuthCheck;
4+
use crate::background_jobs::Job;
45
use axum::body::Bytes;
56
use flate2::read::GzDecoder;
67
use hex::ToHex;
@@ -271,7 +272,13 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
271272
links,
272273
v,
273274
};
274-
worker::add_crate(git_crate).enqueue(conn)?;
275+
276+
if app.config.feature_index_sync {
277+
Job::sync_to_git_index(&git_crate.name).enqueue(conn)?;
278+
Job::sync_to_sparse_index(&git_crate.name).enqueue(conn)?;
279+
} else {
280+
worker::add_crate(git_crate).enqueue(conn)?;
281+
}
275282

276283
// The `other` field on `PublishWarnings` was introduced to handle a temporary warning
277284
// that is no longer needed. As such, crates.io currently does not return any `other`

src/tests/http-data/krate_publish_new_krate_too_big_but_whitelisted.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
],
4545
[
4646
"content-length",
47-
"154"
47+
"309"
4848
],
4949
[
5050
"content-type",
5151
"text/plain"
5252
]
5353
],
54-
"body": "{\"name\":\"foo_whitelist\",\"vers\":\"1.1.0\",\"deps\":[],\"cksum\":\"4e33dc59bbbc96645fc01945fb502507d1b7bd3a2d06227bf7b0fe8842f284c2\",\"features\":{},\"yanked\":false}\n"
54+
"body": "{\"name\":\"foo_whitelist\",\"vers\":\"0.99.0\",\"deps\":[],\"cksum\":\" \",\"features\":{},\"yanked\":false}\n{\"name\":\"foo_whitelist\",\"vers\":\"1.1.0\",\"deps\":[],\"cksum\":\"4e33dc59bbbc96645fc01945fb502507d1b7bd3a2d06227bf7b0fe8842f284c2\",\"features\":{},\"yanked\":false}\n"
5555
},
5656
"response": {
5757
"status": 200,

src/tests/http-data/krate_publish_new_krate_twice.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
],
4545
[
4646
"content-length",
47-
"150"
47+
"301"
4848
],
4949
[
5050
"content-type",
5151
"text/plain"
5252
]
5353
],
54-
"body": "{\"name\":\"foo_twice\",\"vers\":\"2.0.0\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
54+
"body": "{\"name\":\"foo_twice\",\"vers\":\"0.99.0\",\"deps\":[],\"cksum\":\" \",\"features\":{},\"yanked\":false}\n{\"name\":\"foo_twice\",\"vers\":\"2.0.0\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
5555
},
5656
"response": {
5757
"status": 200,

src/tests/http-data/krate_publish_publish_after_removing_documentation.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
],
4545
[
4646
"content-length",
47-
"150"
47+
"300"
4848
],
4949
[
5050
"content-type",
5151
"text/plain"
5252
]
5353
],
54-
"body": "{\"name\":\"docscrate\",\"vers\":\"0.2.1\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
54+
"body": "{\"name\":\"docscrate\",\"vers\":\"0.2.0\",\"deps\":[],\"cksum\":\" \",\"features\":{},\"yanked\":false}\n{\"name\":\"docscrate\",\"vers\":\"0.2.1\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
5555
},
5656
"response": {
5757
"status": 200,
@@ -104,14 +104,14 @@
104104
],
105105
[
106106
"content-length",
107-
"300"
107+
"450"
108108
],
109109
[
110110
"content-type",
111111
"text/plain"
112112
]
113113
],
114-
"body": "{\"name\":\"docscrate\",\"vers\":\"0.2.1\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n{\"name\":\"docscrate\",\"vers\":\"0.2.2\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
114+
"body": "{\"name\":\"docscrate\",\"vers\":\"0.2.0\",\"deps\":[],\"cksum\":\" \",\"features\":{},\"yanked\":false}\n{\"name\":\"docscrate\",\"vers\":\"0.2.1\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n{\"name\":\"docscrate\",\"vers\":\"0.2.2\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
115115
},
116116
"response": {
117117
"status": 200,

src/tests/http-data/team_publish_owned.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
],
4545
[
4646
"content-length",
47-
"155"
47+
"311"
4848
],
4949
[
5050
"content-type",
5151
"text/plain"
5252
]
5353
],
54-
"body": "{\"name\":\"foo_team_owned\",\"vers\":\"2.0.0\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
54+
"body": "{\"name\":\"foo_team_owned\",\"vers\":\"0.99.0\",\"deps\":[],\"cksum\":\" \",\"features\":{},\"yanked\":false}\n{\"name\":\"foo_team_owned\",\"vers\":\"2.0.0\",\"deps\":[],\"cksum\":\"acb5604b126ac894c1eb11c4575bf2072fea61232a888e453770c79d7ed56419\",\"features\":{},\"yanked\":false}\n"
5555
},
5656
"response": {
5757
"status": 200,

src/tests/util/test_app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ fn simple_config() -> config::Server {
359359
version_id_cache_ttl: Duration::from_secs(5 * 60),
360360
cdn_user_agent: "Amazon CloudFront".to_string(),
361361
balance_capacity: BalanceCapacityConfig::for_testing(),
362+
feature_index_sync: true,
362363
}
363364
}
364365

0 commit comments

Comments
 (0)