Skip to content

Commit 57ec61a

Browse files
authored
Use db_write() instead of the primary_database field (#7188)
1 parent 65e31bc commit 57ec61a

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

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
}
7272

7373
conduit_compat(move || {
74-
let conn = &mut *app.primary_database.get()?;
74+
let conn = &mut *app.db_write()?;
7575

7676
// this query should only be used for the endpoint scope calculation
7777
// since a race condition there would only cause `publish-new` instead of

src/downloads_counter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ impl DownloadsCounter {
6565
}
6666

6767
pub fn persist_all_shards(&self, app: &App) -> Result<PersistStats, Error> {
68-
let conn = &mut app.primary_database.get()?;
68+
let conn = &mut app.db_write()?;
6969
self.persist_all_shards_with_conn(conn)
7070
}
7171

7272
pub fn persist_next_shard(&self, app: &App) -> Result<PersistStats, Error> {
73-
let conn = &mut app.primary_database.get()?;
73+
let conn = &mut app.db_write()?;
7474
self.persist_next_shard_with_conn(conn)
7575
}
7676

src/tests/all.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,6 @@ fn recursive_get_of_db_conn_in_tests_will_panic() {
169169
let (app, _) = TestApp::init().empty();
170170
let app = app.as_inner();
171171

172-
let _conn1 = app.primary_database.get().unwrap();
173-
let _conn2 = app.primary_database.get().unwrap();
172+
let _conn1 = app.db_write().unwrap();
173+
let _conn2 = app.db_write().unwrap();
174174
}

src/tests/util/test_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Drop for TestAppInner {
5050

5151
// Manually verify that all jobs have completed successfully
5252
// This will catch any tests that enqueued a job but forgot to initialize the runner
53-
let conn = &mut *self.app.primary_database.get().unwrap();
53+
let conn = &mut *self.app.db_write().unwrap();
5454
let job_count: i64 = background_jobs.count().get_result(conn).unwrap();
5555
assert_eq!(
5656
0, job_count,
@@ -95,7 +95,7 @@ impl TestApp {
9595
/// connection before making any API calls. Once the closure returns, the connection is
9696
/// dropped, ensuring it is returned to the pool and available for any future API calls.
9797
pub fn db<T, F: FnOnce(&mut PgConnection) -> T>(&self, f: F) -> T {
98-
let conn = &mut self.0.app.primary_database.get().unwrap();
98+
let conn = &mut self.0.app.db_write().unwrap();
9999
f(conn)
100100
}
101101

0 commit comments

Comments
 (0)