Skip to content

Commit bc39020

Browse files
committed
models/krate: Remove sync fns
1 parent 2daa022 commit bc39020

File tree

5 files changed

+7
-47
lines changed

5 files changed

+7
-47
lines changed

src/controllers/krate/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
122122
};
123123

124124
let top_versions = if include.versions {
125-
Some(krate.async_top_versions(&mut conn).await?)
125+
Some(krate.top_versions(&mut conn).await?)
126126
} else {
127127
None
128128
};

src/controllers/krate/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
344344

345345
// To avoid race conditions, we try to insert
346346
// first so we know whether to add an owner
347-
let krate = match persist.async_create(conn, user.id).await.optional()? {
347+
let krate = match persist.create(conn, user.id).await.optional()? {
348348
Some(krate) => krate,
349349
None => persist.update(conn).await?,
350350
};
@@ -480,7 +480,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
480480
return Err(bad_request(format!("The following category slugs are not currently supported on crates.io: {}\n\nSee https://{}/category_slugs for a list of supported slugs.", unknown_categories, domain)));
481481
}
482482

483-
let top_versions = krate.async_top_versions(conn).await?;
483+
let top_versions = krate.top_versions(conn).await?;
484484

485485
let downloads: i64 = crate_downloads::table.select(crate_downloads::downloads)
486486
.filter(crate_downloads::crate_id.eq(krate.id))

src/models/krate.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> NewCrate<'a> {
126126
.await
127127
}
128128

129-
pub async fn async_create(
129+
pub async fn create(
130130
&self,
131131
conn: &mut AsyncPgConnection,
132132
user_id: i32,
@@ -161,32 +161,6 @@ impl<'a> NewCrate<'a> {
161161
})
162162
.await
163163
}
164-
165-
pub fn create(&self, conn: &mut impl Conn, user_id: i32) -> QueryResult<Crate> {
166-
use diesel::RunQueryDsl;
167-
168-
conn.transaction(|conn| {
169-
let krate: Crate = diesel::insert_into(crates::table)
170-
.values(self)
171-
.on_conflict_do_nothing()
172-
.returning(Crate::as_returning())
173-
.get_result(conn)?;
174-
175-
let owner = CrateOwner {
176-
crate_id: krate.id,
177-
owner_id: user_id,
178-
created_by: user_id,
179-
owner_kind: OwnerKind::User,
180-
email_notifications: true,
181-
};
182-
183-
diesel::insert_into(crate_owners::table)
184-
.values(&owner)
185-
.execute(conn)?;
186-
187-
Ok(krate)
188-
})
189-
}
190164
}
191165

192166
impl Crate {
@@ -382,7 +356,7 @@ impl Crate {
382356
/// Return both the newest (most recently updated) and
383357
/// highest version (in semver order) for the current crate,
384358
/// where all top versions are not yanked.
385-
pub async fn async_top_versions(
359+
pub async fn top_versions(
386360
&self,
387361
conn: &mut AsyncPgConnection,
388362
) -> QueryResult<TopVersions> {
@@ -397,20 +371,6 @@ impl Crate {
397371
))
398372
}
399373

400-
/// Return both the newest (most recently updated) and
401-
/// highest version (in semver order) for the current crate,
402-
/// where all top versions are not yanked.
403-
pub fn top_versions(&self, conn: &mut impl Conn) -> QueryResult<TopVersions> {
404-
use diesel::RunQueryDsl;
405-
406-
Ok(TopVersions::from_date_version_pairs(
407-
Version::belonging_to(self)
408-
.filter(versions::yanked.eq(false))
409-
.select((versions::created_at, versions::num))
410-
.load(conn)?,
411-
))
412-
}
413-
414374
pub async fn async_owners(&self, conn: &mut AsyncPgConnection) -> QueryResult<Vec<Owner>> {
415375
use diesel_async::RunQueryDsl;
416376

src/tests/builders/krate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a> CrateBuilder<'a> {
122122
use diesel::{insert_into, select, update};
123123
use diesel_async::RunQueryDsl;
124124

125-
let mut krate = self.krate.async_create(connection, self.owner_id).await?;
125+
let mut krate = self.krate.create(connection, self.owner_id).await?;
126126

127127
// Since we are using `NewCrate`, we can't set all the
128128
// crate properties in a single DB call.

src/worker/jobs/downloads/update_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ mod tests {
124124
name: "foo",
125125
..Default::default()
126126
}
127-
.async_create(conn, user_id)
127+
.create(conn, user_id)
128128
.await
129129
.unwrap();
130130

0 commit comments

Comments
 (0)