Skip to content

Commit a0cd9f0

Browse files
authored
deadpool: Drop obsolete async suffixes (#8447)
This commit renames a couple of struct fields and functions to remove `async` and `deadpool` pre-/suffixes. This distinction is no longer needed, since we don't use sync database connection pools anymore.
1 parent 81df0a7 commit a0cd9f0

25 files changed

+74
-76
lines changed

src/app.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ type DeadpoolResult = Result<deadpool_diesel::postgres::Connection, deadpool_die
2121
/// The `App` struct holds the main components of the application like
2222
/// the database connection pool and configurations
2323
pub struct App {
24-
/// Async database connection pool based on `deadpool` connected
25-
/// to the primary database
26-
pub deadpool_primary: DeadpoolPool,
24+
/// Database connection pool connected to the primary database
25+
pub primary_database: DeadpoolPool,
2726

28-
/// Async database connection pool based on `deadpool` connected
29-
/// to the read-only replica database
30-
pub deadpool_replica: Option<DeadpoolPool>,
27+
/// Database connection pool connected to the read-only replica database
28+
pub replica_database: Option<DeadpoolPool>,
3129

3230
/// GitHub API client
3331
pub github: Box<dyn GitHubClient>,
@@ -80,7 +78,7 @@ impl App {
8078
),
8179
);
8280

83-
let primary_database_async = {
81+
let primary_database = {
8482
use secrecy::ExposeSecret;
8583

8684
let primary_db_connection_config = ConnectionConfig {
@@ -100,7 +98,7 @@ impl App {
10098
.unwrap()
10199
};
102100

103-
let replica_database_async = if let Some(pool_config) = config.db.replica.as_ref() {
101+
let replica_database = if let Some(pool_config) = config.db.replica.as_ref() {
104102
use secrecy::ExposeSecret;
105103

106104
let replica_db_connection_config = ConnectionConfig {
@@ -125,8 +123,8 @@ impl App {
125123
};
126124

127125
App {
128-
deadpool_primary: primary_database_async,
129-
deadpool_replica: replica_database_async,
126+
primary_database,
127+
replica_database,
130128
github,
131129
github_oauth,
132130
emails,
@@ -146,18 +144,18 @@ impl App {
146144

147145
/// Obtain a read/write database connection from the async primary pool
148146
#[instrument(skip_all)]
149-
pub async fn db_write_async(&self) -> DeadpoolResult {
150-
self.deadpool_primary.get().await
147+
pub async fn db_write(&self) -> DeadpoolResult {
148+
self.primary_database.get().await
151149
}
152150

153151
/// Obtain a readonly database connection from the replica pool
154152
///
155153
/// If the replica pool is disabled or unavailable, the primary pool is used instead.
156154
#[instrument(skip_all)]
157-
pub async fn db_read_async(&self) -> DeadpoolResult {
158-
let Some(read_only_pool) = self.deadpool_replica.as_ref() else {
155+
pub async fn db_read(&self) -> DeadpoolResult {
156+
let Some(read_only_pool) = self.replica_database.as_ref() else {
159157
// Replica is disabled, but primary might be available
160-
return self.deadpool_primary.get().await;
158+
return self.primary_database.get().await;
161159
};
162160

163161
match read_only_pool.get().await {
@@ -173,7 +171,7 @@ impl App {
173171
.map(|metric| metric.inc());
174172

175173
warn!("Replica is unavailable, falling back to primary ({error})");
176-
self.deadpool_primary.get().await
174+
self.primary_database.get().await
177175
}
178176

179177
// Replica failed
@@ -185,12 +183,12 @@ impl App {
185183
///
186184
/// If the primary pool is unavailable, the replica pool is used instead, if not disabled.
187185
#[instrument(skip_all)]
188-
pub async fn db_read_prefer_primary_async(&self) -> DeadpoolResult {
189-
let Some(read_only_pool) = self.deadpool_replica.as_ref() else {
190-
return self.deadpool_primary.get().await;
186+
pub async fn db_read_prefer_primary(&self) -> DeadpoolResult {
187+
let Some(read_only_pool) = self.replica_database.as_ref() else {
188+
return self.primary_database.get().await;
191189
};
192190

193-
match self.deadpool_primary.get().await {
191+
match self.primary_database.get().await {
194192
// Primary is available
195193
Ok(connection) => Ok(connection),
196194

src/controllers/category.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub async fn index(app: AppState, req: Parts) -> AppResult<Json<Value>> {
1212
// to paginate this.
1313
let options = PaginationOptions::builder().gather(&req)?;
1414

15-
let conn = app.db_read_async().await?;
15+
let conn = app.db_read().await?;
1616
conn.interact(move |conn| {
1717
let query = req.query();
1818
let sort = query.get("sort").map_or("alpha", String::as_str);
@@ -38,7 +38,7 @@ pub async fn index(app: AppState, req: Parts) -> AppResult<Json<Value>> {
3838

3939
/// Handles the `GET /categories/:category_id` route.
4040
pub async fn show(state: AppState, Path(slug): Path<String>) -> AppResult<Json<Value>> {
41-
let conn = state.db_read_async().await?;
41+
let conn = state.db_read().await?;
4242
conn.interact(move |conn| {
4343
let cat: Category = Category::by_slug(&slug).first(conn)?;
4444
let subcats = cat
@@ -71,7 +71,7 @@ pub async fn show(state: AppState, Path(slug): Path<String>) -> AppResult<Json<V
7171

7272
/// Handles the `GET /category_slugs` route.
7373
pub async fn slugs(state: AppState) -> AppResult<Json<Value>> {
74-
let conn = state.db_read_async().await?;
74+
let conn = state.db_read().await?;
7575
conn.interact(move |conn| {
7676
let slugs: Vec<Slug> = categories::table
7777
.select((categories::slug, categories::slug, categories::description))

src/controllers/crate_owner_invitation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tokio::runtime::Handle;
1818

1919
/// Handles the `GET /api/v1/me/crate_owner_invitations` route.
2020
pub async fn list(app: AppState, req: Parts) -> AppResult<Json<Value>> {
21-
let conn = app.db_read_async().await?;
21+
let conn = app.db_read().await?;
2222
conn.interact(move |conn| {
2323
let auth = AuthCheck::only_cookie().check(&req, conn)?;
2424
let user_id = auth.user_id();
@@ -58,7 +58,7 @@ pub async fn list(app: AppState, req: Parts) -> AppResult<Json<Value>> {
5858

5959
/// Handles the `GET /api/private/crate_owner_invitations` route.
6060
pub async fn private_list(app: AppState, req: Parts) -> AppResult<Json<PrivateListResponse>> {
61-
let conn = app.db_read_async().await?;
61+
let conn = app.db_read().await?;
6262
conn.interact(move |conn| {
6363
let auth = AuthCheck::only_cookie().check(&req, conn)?;
6464

@@ -265,7 +265,7 @@ pub async fn handle_invite(state: AppState, req: BytesRequest) -> AppResult<Json
265265

266266
let crate_invite = crate_invite.crate_owner_invite;
267267

268-
let conn = state.db_write_async().await?;
268+
let conn = state.db_write().await?;
269269
conn.interact(move |conn| {
270270
let auth = AuthCheck::default().check(&req, conn)?;
271271
let user_id = auth.user_id();
@@ -289,7 +289,7 @@ pub async fn handle_invite_with_token(
289289
state: AppState,
290290
Path(token): Path<String>,
291291
) -> AppResult<Json<Value>> {
292-
let conn = state.db_write_async().await?;
292+
let conn = state.db_write().await?;
293293
conn.interact(move |conn| {
294294
let config = &state.config;
295295

src/controllers/github/secret_scanning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub async fn verify(
255255
let alerts: Vec<GitHubSecretAlert> = json::from_slice(&body)
256256
.map_err(|e| bad_request(format!("invalid secret alert request: {e:?}")))?;
257257

258-
let conn = state.db_write_async().await?;
258+
let conn = state.db_write().await?;
259259
conn.interact(move |conn| {
260260
let feedback = alerts
261261
.into_iter()

src/controllers/keyword.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn index(state: AppState, qp: Query<IndexQuery>, req: Parts) -> AppRes
2626

2727
let query = query.pages_pagination(PaginationOptions::builder().gather(&req)?);
2828

29-
let conn = state.db_read_async().await?;
29+
let conn = state.db_read().await?;
3030
conn.interact(move |conn| {
3131
let data: Paginated<Keyword> = query.load(conn)?;
3232
let total = data.total();
@@ -45,7 +45,7 @@ pub async fn index(state: AppState, qp: Query<IndexQuery>, req: Parts) -> AppRes
4545

4646
/// Handles the `GET /keywords/:keyword_id` route.
4747
pub async fn show(Path(name): Path<String>, state: AppState) -> AppResult<Json<Value>> {
48-
let conn = &mut state.db_read_async().await?;
48+
let conn = &mut state.db_read().await?;
4949
conn.interact(move |conn| {
5050
let kw = Keyword::find_by_keyword(conn, &name)?;
5151

src/controllers/krate/downloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::views::EncodableVersionDownload;
1515

1616
/// Handles the `GET /crates/:crate_id/downloads` route.
1717
pub async fn downloads(state: AppState, Path(crate_name): Path<String>) -> AppResult<Json<Value>> {
18-
let conn = state.db_read_async().await?;
18+
let conn = state.db_read().await?;
1919
conn.interact(move |conn| {
2020
use diesel::dsl::*;
2121
use diesel::sql_types::BigInt;

src/controllers/krate/follow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub async fn follow(
2424
Path(crate_name): Path<String>,
2525
req: Parts,
2626
) -> AppResult<Response> {
27-
let conn = app.db_write_async().await?;
27+
let conn = app.db_write().await?;
2828
conn.interact(move |conn| {
2929
let user_id = AuthCheck::default().check(&req, conn)?.user_id();
3030
let follow = follow_target(&crate_name, conn, user_id)?;
@@ -44,7 +44,7 @@ pub async fn unfollow(
4444
Path(crate_name): Path<String>,
4545
req: Parts,
4646
) -> AppResult<Response> {
47-
let conn = app.db_write_async().await?;
47+
let conn = app.db_write().await?;
4848
conn.interact(move |conn| {
4949
let user_id = AuthCheck::default().check(&req, conn)?.user_id();
5050
let follow = follow_target(&crate_name, conn, user_id)?;
@@ -61,7 +61,7 @@ pub async fn following(
6161
Path(crate_name): Path<String>,
6262
req: Parts,
6363
) -> AppResult<Json<Value>> {
64-
let conn = app.db_read_prefer_primary_async().await?;
64+
let conn = app.db_read_prefer_primary().await?;
6565
conn.interact(move |conn| {
6666
use diesel::dsl::exists;
6767

src/controllers/krate/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub async fn show_new(app: AppState, req: Parts) -> AppResult<Json<Value>> {
2727

2828
/// Handles the `GET /crates/:crate_id` route.
2929
pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppResult<Json<Value>> {
30-
let conn = app.db_read_async().await?;
30+
let conn = app.db_read().await?;
3131
conn.interact(move |conn| {
3232
let include = req
3333
.query()
@@ -227,7 +227,7 @@ pub async fn reverse_dependencies(
227227
Path(name): Path<String>,
228228
req: Parts,
229229
) -> AppResult<Json<Value>> {
230-
let conn = app.db_read_async().await?;
230+
let conn = app.db_read().await?;
231231
conn.interact(move |conn| {
232232
let pagination_options = PaginationOptions::builder().gather(&req)?;
233233

src/controllers/krate/owners.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tokio::runtime::Handle;
1010

1111
/// Handles the `GET /crates/:crate_id/owners` route.
1212
pub async fn owners(state: AppState, Path(crate_name): Path<String>) -> AppResult<Json<Value>> {
13-
let conn = state.db_read_async().await?;
13+
let conn = state.db_read().await?;
1414
conn.interact(move |conn| {
1515
let krate: Crate = Crate::by_name(&crate_name)
1616
.first(conn)
@@ -30,7 +30,7 @@ pub async fn owners(state: AppState, Path(crate_name): Path<String>) -> AppResul
3030

3131
/// Handles the `GET /crates/:crate_id/owner_team` route.
3232
pub async fn owner_team(state: AppState, Path(crate_name): Path<String>) -> AppResult<Json<Value>> {
33-
let conn = state.db_read_async().await?;
33+
let conn = state.db_read().await?;
3434
conn.interact(move |conn| {
3535
let krate: Crate = Crate::by_name(&crate_name)
3636
.first(conn)
@@ -49,7 +49,7 @@ pub async fn owner_team(state: AppState, Path(crate_name): Path<String>) -> AppR
4949

5050
/// Handles the `GET /crates/:crate_id/owner_user` route.
5151
pub async fn owner_user(state: AppState, Path(crate_name): Path<String>) -> AppResult<Json<Value>> {
52-
let conn = state.db_read_async().await?;
52+
let conn = state.db_read().await?;
5353
conn.interact(move |conn| {
5454
let krate: Crate = Crate::by_name(&crate_name)
5555
.first(conn)
@@ -101,7 +101,7 @@ async fn modify_owners(
101101
) -> AppResult<Json<Value>> {
102102
let logins = body.owners;
103103

104-
let conn = app.db_write_async().await?;
104+
let conn = app.db_write().await?;
105105
conn.interact(move |conn| {
106106
let auth = AuthCheck::default()
107107
.with_endpoint_scope(EndpointScope::ChangeOwners)

src/controllers/krate/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
7171
request_log.add("crate_name", &*metadata.name);
7272
request_log.add("crate_version", &version_string);
7373

74-
let conn = app.db_write_async().await?;
74+
let conn = app.db_write().await?;
7575
conn.interact(move |conn| {
7676

7777
// this query should only be used for the endpoint scope calculation

src/controllers/krate/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::sql::{array_agg, canon_crate_name, lower};
3939
/// function out to cover the different use cases, and create unit tests
4040
/// for them.
4141
pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
42-
let conn = app.db_read_async().await?;
42+
let conn = app.db_read().await?;
4343
conn.interact(move |conn| {
4444
use diesel::sql_types::Float;
4545
use seek::*;

src/controllers/krate/versions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn versions(
1919
Path(crate_name): Path<String>,
2020
req: Parts,
2121
) -> AppResult<Json<Value>> {
22-
let conn = state.db_read_async().await?;
22+
let conn = state.db_read().await?;
2323
conn.interact(move |conn| {
2424
let crate_id: i32 = Crate::by_name(&crate_name)
2525
.select(crates::id)

src/controllers/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub async fn prometheus(app: AppState, Path(kind): Path<String>, req: Parts) ->
2323

2424
let metrics = match kind.as_str() {
2525
"service" => {
26-
let conn = app.db_read_async().await?;
26+
let conn = app.db_read().await?;
2727
conn.interact(move |conn| app.service_metrics.gather(conn))
2828
.await??
2929
}

src/controllers/summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde_json::Value;
99

1010
/// Handles the `GET /summary` route.
1111
pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
12-
let conn = state.db_read_async().await?;
12+
let conn = state.db_read().await?;
1313
conn.interact(move |conn| {
1414
let config = &state.config;
1515

src/controllers/team.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::views::EncodableTeam;
88
pub async fn show_team(state: AppState, Path(name): Path<String>) -> AppResult<Json<Value>> {
99
use self::teams::dsl::{login, teams};
1010

11-
let conn = state.db_read_async().await?;
11+
let conn = state.db_read().await?;
1212
let team: Team = conn
1313
.interact(move |conn| teams.filter(login.eq(&name)).first(conn))
1414
.await??;

src/controllers/token.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub async fn list(
3535
Query(params): Query<GetParams>,
3636
req: Parts,
3737
) -> AppResult<Json<Value>> {
38-
let conn = &mut *app.db_read_prefer_primary_async().await?;
38+
let conn = &mut *app.db_read_prefer_primary().await?;
3939
conn.interact(move |conn| {
4040
let auth = AuthCheck::only_cookie().check(&req, conn)?;
4141
let user = auth.user();
@@ -58,7 +58,7 @@ pub async fn list(
5858

5959
/// Handles the `PUT /me/tokens` route.
6060
pub async fn new(app: AppState, req: BytesRequest) -> AppResult<Json<Value>> {
61-
let conn = &mut *app.db_write_async().await?;
61+
let conn = &mut *app.db_write().await?;
6262
conn.interact(move |conn| {
6363
/// The incoming serialization format for the `ApiToken` model.
6464
#[derive(Deserialize)]
@@ -142,7 +142,7 @@ pub async fn new(app: AppState, req: BytesRequest) -> AppResult<Json<Value>> {
142142

143143
/// Handles the `DELETE /me/tokens/:id` route.
144144
pub async fn revoke(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult<Json<Value>> {
145-
let conn = &mut *app.db_write_async().await?;
145+
let conn = &mut *app.db_write().await?;
146146
conn.interact(move |conn| {
147147
let auth = AuthCheck::default().check(&req, conn)?;
148148
let user = auth.user();
@@ -157,7 +157,7 @@ pub async fn revoke(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult
157157

158158
/// Handles the `DELETE /tokens/current` route.
159159
pub async fn revoke_current(app: AppState, req: Parts) -> AppResult<Response> {
160-
let conn = &mut *app.db_write_async().await?;
160+
let conn = &mut *app.db_write().await?;
161161
conn.interact(move |conn| {
162162
let auth = AuthCheck::default().check(&req, conn)?;
163163
let api_token_id = auth

0 commit comments

Comments
 (0)