Skip to content

Commit 7cd2a57

Browse files
committed
Fix new issues after rebase
1 parent b24270e commit 7cd2a57

File tree

11 files changed

+38
-37
lines changed

11 files changed

+38
-37
lines changed

src/background_jobs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Job {
5858
}
5959
}
6060

61-
pub fn enqueue(&self, conn: &PgConnection) -> Result<(), EnqueueError> {
61+
pub fn enqueue(&self, conn: &mut PgConnection) -> Result<(), EnqueueError> {
6262
use crate::schema::background_jobs::dsl::*;
6363

6464
let job_data = self.to_value()?;

src/controllers/github/secret_scanning.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ fn alert_revoke_token(
155155
state: &AppState,
156156
alert: &GitHubSecretAlert,
157157
) -> Result<GitHubSecretAlertFeedbackLabel, Box<dyn AppError>> {
158-
let conn = state.db_write()?;
158+
let conn = &mut *state.db_write()?;
159159

160160
let hashed_token = SecureToken::hash(&alert.token);
161161

162162
// Not using `ApiToken::find_by_api_token()` in order to preserve `last_used_at`
163163
let token = api_tokens::table
164164
.filter(api_tokens::token.eq(hashed_token))
165-
.get_result::<ApiToken>(&*conn)
165+
.get_result::<ApiToken>(conn)
166166
.optional()?;
167167

168168
let Some(token) = token else {
@@ -180,7 +180,7 @@ fn alert_revoke_token(
180180

181181
diesel::update(&token)
182182
.set(api_tokens::revoked.eq(true))
183-
.execute(&*conn)?;
183+
.execute(conn)?;
184184

185185
warn!(
186186
token_id = %token.id, user_id = %token.user_id,
@@ -202,10 +202,10 @@ fn send_notification_email(
202202
alert: &GitHubSecretAlert,
203203
state: &AppState,
204204
) -> anyhow::Result<()> {
205-
let conn = state.db_read()?;
205+
let conn = &mut state.db_read()?;
206206

207-
let user = User::find(&conn, token.user_id).context("Failed to find user")?;
208-
let Some(email) = user.email(&conn)? else {
207+
let user = User::find(conn, token.user_id).context("Failed to find user")?;
208+
let Some(email) = user.email(conn)? else {
209209
return Err(anyhow!("No address found"));
210210
};
211211

src/controllers/krate/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn versions(req: &mut dyn RequestExt) -> EndpointResult {
351351
pub fn reverse_dependencies(req: &mut dyn RequestExt) -> EndpointResult {
352352
let pagination_options = PaginationOptions::builder().gather(req)?;
353353
let name = &req.params()["crate_id"];
354-
let conn = &mut req.app().db_read()?;
354+
let conn = &mut *req.app().db_read()?;
355355
let krate: Crate = Crate::by_name(name).first(conn)?;
356356
let (rev_deps, total) = krate.reverse_dependencies(conn, pagination_options)?;
357357
let rev_deps: Vec<_> = rev_deps

src/controllers/krate/publish.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
6969
// since a race condition there would only cause `publish-new` instead of
7070
// `publish-update` to be used.
7171
let existing_crate = Crate::by_name(&new_crate.name)
72-
.first::<Crate>(&*conn)
72+
.first::<Crate>(conn)
7373
.optional()?;
7474

7575
let endpoint_scope = match existing_crate {
@@ -146,7 +146,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
146146
}
147147

148148
if let Some(daily_version_limit) = app.config.new_version_rate_limit {
149-
let published_today = count_versions_published_today(krate.id, &conn)?;
149+
let published_today = count_versions_published_today(krate.id, conn)?;
150150
if published_today >= daily_version_limit as i64 {
151151
return Err(cargo_err(
152152
"You have published too many versions of this crate in the last 24 hours",
@@ -287,7 +287,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
287287

288288
/// Counts the number of versions for `krate_id` that were published within
289289
/// the last 24 hours.
290-
fn count_versions_published_today(krate_id: i32, conn: &PgConnection) -> QueryResult<i64> {
290+
fn count_versions_published_today(krate_id: i32, conn: &mut PgConnection) -> QueryResult<i64> {
291291
use crate::schema::versions::dsl::*;
292292
use diesel::dsl::{now, IntervalDsl};
293293

src/controllers/version/yank.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fn modify_yank(req: &mut dyn RequestExt, yanked: bool) -> EndpointResult {
4040
.for_crate(crate_name)
4141
.check(req)?;
4242

43-
let state = &mut *req.app();
44-
let conn = &mut state.db_write()?;
43+
let state = req.app();
44+
let conn = &mut *state.db_write()?;
4545
let (version, krate) = version_and_crate(conn, crate_name, semver)?;
4646
let api_token_id = auth.api_token_id();
4747
let user = auth.user();

src/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ pub enum DieselPool {
2525
Test(Arc<ReentrantMutex<PgConnection>>),
2626
}
2727

28-
type Callback<'a> = &'a dyn Fn(&PgConnection) -> Result<(), Box<dyn Error>>;
28+
type Callback<'a> = &'a dyn Fn(&mut PgConnection) -> Result<(), Box<dyn Error>>;
2929

3030
impl DieselPool {
3131
pub(crate) fn with_connection(&self, f: Callback<'_>) -> Result<(), Box<dyn Error>> {
3232
match self {
3333
DieselPool::Pool { pool, .. } | DieselPool::BackgroundJobPool { pool } => {
34-
f(&*pool.get()?)
34+
f(&mut *pool.get()?)
3535
}
36-
DieselPool::Test(connection) => f(&connection.lock()),
36+
DieselPool::Test(connection) => f(&mut connection.lock()),
3737
}
3838
}
3939

src/models/token/scopes.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl From<&EndpointScope> for &[u8] {
2626
}
2727

2828
impl ToSql<Text, Pg> for EndpointScope {
29-
fn to_sql<W: Write>(&self, out: &mut Output<'_, W, Pg>) -> serialize::Result {
29+
fn to_sql(&self, out: &mut Output<'_, '_, Pg>) -> serialize::Result {
3030
out.write_all(self.into())?;
3131
Ok(IsNull::No)
3232
}
@@ -47,8 +47,9 @@ impl TryFrom<&[u8]> for EndpointScope {
4747
}
4848

4949
impl FromSql<Text, Pg> for EndpointScope {
50-
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
51-
Ok(EndpointScope::try_from(not_none!(bytes))?)
50+
fn from_sql(bytes: diesel::pg::PgValue<'_>) -> deserialize::Result<Self> {
51+
let value = <String as FromSql<Text, Pg>>::from_sql(bytes)?;
52+
Ok(EndpointScope::try_from(value.as_bytes())?)
5253
}
5354
}
5455

@@ -82,15 +83,15 @@ impl TryFrom<String> for CrateScope {
8283
}
8384

8485
impl FromSql<Text, Pg> for CrateScope {
85-
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
86+
fn from_sql(bytes: diesel::pg::PgValue<'_>) -> deserialize::Result<Self> {
8687
let value = <String as FromSql<Text, Pg>>::from_sql(bytes)?;
8788
Ok(CrateScope::try_from(value)?)
8889
}
8990
}
9091

9192
impl ToSql<Text, Pg> for CrateScope {
92-
fn to_sql<W: Write>(&self, out: &mut Output<'_, W, Pg>) -> serialize::Result {
93-
<String as ToSql<Text, Pg>>::to_sql(&self.pattern, out)
93+
fn to_sql(&self, out: &mut Output<'_, '_, Pg>) -> serialize::Result {
94+
ToSql::<Text, Pg>::to_sql(&self.pattern, &mut out.reborrow())
9495
}
9596
}
9697

src/swirl/runner.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Runner {
140140
// The connection may not be `Send` so we need to clone the pool instead
141141
let pool = self.connection_pool.clone();
142142
self.thread_pool.execute(move || {
143-
let conn = &*match pool.get() {
143+
let conn = &mut *match pool.get() {
144144
Ok(conn) => conn,
145145
Err(e) => {
146146
// TODO: Review error handling and possibly drop all usage of `let _ =` in this file
@@ -149,7 +149,7 @@ impl Runner {
149149
}
150150
};
151151

152-
let job_run_result = conn.transaction::<_, diesel::result::Error, _>(|| {
152+
let job_run_result = conn.transaction::<_, diesel::result::Error, _>(|conn| {
153153
let job = match storage::find_next_unlocked_job(conn).optional() {
154154
Ok(Some(j)) => {
155155
let _ = sender.send(Event::Working);
@@ -205,7 +205,7 @@ impl Runner {
205205
// FIXME: Only public for `src/tests/util/test_app.rs`
206206
pub fn check_for_failed_jobs(&self) -> Result<(), FailedJobsError> {
207207
self.wait_for_jobs()?;
208-
let failed_jobs = storage::failed_job_count(&*self.connection()?)?;
208+
let failed_jobs = storage::failed_job_count(&mut *self.connection()?)?;
209209
if failed_jobs == 0 {
210210
Ok(())
211211
} else {
@@ -298,7 +298,7 @@ mod tests {
298298

299299
let remaining_jobs = background_jobs
300300
.count()
301-
.get_result(&*runner.connection().unwrap());
301+
.get_result(&mut *runner.connection().unwrap());
302302
assert_eq!(Ok(0), remaining_jobs);
303303
}
304304

@@ -317,7 +317,7 @@ mod tests {
317317
Err("nope".into())
318318
});
319319

320-
let conn = &*runner.connection().unwrap();
320+
let conn = &mut *runner.connection().unwrap();
321321
// Wait for the first thread to acquire the lock
322322
barrier2.0.wait();
323323
// We are intentionally not using `get_single_job` here.
@@ -357,7 +357,7 @@ mod tests {
357357
.find(job_id)
358358
.select(retries)
359359
.for_update()
360-
.first::<i32>(&*runner.connection().unwrap())
360+
.first::<i32>(&mut *runner.connection().unwrap())
361361
.unwrap();
362362
assert_eq!(1, tries);
363363
}
@@ -381,7 +381,7 @@ mod tests {
381381
impl<'a> Drop for TestGuard<'a> {
382382
fn drop(&mut self) {
383383
::diesel::sql_query("TRUNCATE TABLE background_jobs")
384-
.execute(&*runner().connection().unwrap())
384+
.execute(&mut *runner().connection().unwrap())
385385
.unwrap();
386386
}
387387
}
@@ -397,7 +397,7 @@ mod tests {
397397
::diesel::insert_into(background_jobs)
398398
.values((job_type.eq("Foo"), data.eq(serde_json::json!(null))))
399399
.returning((id, job_type, data))
400-
.get_result(&*runner.connection().unwrap())
400+
.get_result(&mut *runner.connection().unwrap())
401401
.unwrap()
402402
}
403403
}

src/swirl/storage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn retriable() -> Box<dyn BoxableExpression<background_jobs::table, Pg, SqlType
2424

2525
/// Finds the next job that is unlocked, and ready to be retried. If a row is
2626
/// found, it will be locked.
27-
pub(super) fn find_next_unlocked_job(conn: &PgConnection) -> QueryResult<BackgroundJob> {
27+
pub(super) fn find_next_unlocked_job(conn: &mut PgConnection) -> QueryResult<BackgroundJob> {
2828
use schema::background_jobs::dsl::*;
2929

3030
background_jobs
@@ -37,7 +37,7 @@ pub(super) fn find_next_unlocked_job(conn: &PgConnection) -> QueryResult<Backgro
3737
}
3838

3939
/// The number of jobs that have failed at least once
40-
pub(super) fn failed_job_count(conn: &PgConnection) -> QueryResult<i64> {
40+
pub(super) fn failed_job_count(conn: &mut PgConnection) -> QueryResult<i64> {
4141
use schema::background_jobs::dsl::*;
4242

4343
background_jobs
@@ -47,7 +47,7 @@ pub(super) fn failed_job_count(conn: &PgConnection) -> QueryResult<i64> {
4747
}
4848

4949
/// Deletes a job that has successfully completed running
50-
pub(super) fn delete_successful_job(conn: &PgConnection, job_id: i64) -> QueryResult<()> {
50+
pub(super) fn delete_successful_job(conn: &mut PgConnection, job_id: i64) -> QueryResult<()> {
5151
use schema::background_jobs::dsl::*;
5252

5353
delete(background_jobs.find(job_id)).execute(conn)?;
@@ -58,7 +58,7 @@ pub(super) fn delete_successful_job(conn: &PgConnection, job_id: i64) -> QueryRe
5858
///
5959
/// Ignores any database errors that may have occurred. If the DB has gone away,
6060
/// we assume that just trying again with a new connection will succeed.
61-
pub(super) fn update_failed_job(conn: &PgConnection, job_id: i64) {
61+
pub(super) fn update_failed_job(conn: &mut PgConnection, job_id: i64) {
6262
use schema::background_jobs::dsl::*;
6363

6464
let _ = update(background_jobs.find(job_id))

src/worker/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::process::Command;
1414
#[instrument(skip_all, fields(krate.name = ?krate.name, krate.vers = ?krate.vers))]
1515
pub fn perform_index_add_crate(
1616
env: &Environment,
17-
conn: &PgConnection,
17+
conn: &mut PgConnection,
1818
krate: &Crate,
1919
) -> Result<(), PerformError> {
2020
info!("Syncing git index to HTTP-based index");

src/worker/update_downloads.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fn update(conn: &mut PgConnection) -> QueryResult<()> {
4040
.execute(conn)?;
4141
info!("Finished freezing old version_downloads");
4242

43-
no_arg_sql_function!(refresh_recent_crate_downloads, ());
44-
select(refresh_recent_crate_downloads).execute(conn)?;
43+
sql_function!(fn refresh_recent_crate_downloads());
44+
select(refresh_recent_crate_downloads()).execute(conn)?;
4545
println!("Finished running refresh_recent_crate_downloads");
4646

4747
Ok(())

0 commit comments

Comments
 (0)