Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/controllers/krate/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,22 @@ pub async fn owners(state: AppState, Path(crate_name): Path<String>) -> AppResul

/// Handles the `GET /crates/:crate_id/owner_team` route.
pub async fn owner_team(state: AppState, Path(crate_name): Path<String>) -> AppResult<Json<Value>> {
let conn = state.db_read().await?;
spawn_blocking(move || {
use diesel::RunQueryDsl;

let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
use diesel_async::RunQueryDsl;

let krate: Crate = Crate::by_name(&crate_name)
.first(conn)
.optional()?
.ok_or_else(|| crate_not_found(&crate_name))?;
let mut conn = state.db_read().await?;
let krate: Crate = Crate::by_name(&crate_name)
.first(&mut conn)
.await
.optional()?
.ok_or_else(|| crate_not_found(&crate_name))?;

let owners = Team::owning(&krate, conn)?
.into_iter()
.map(Owner::into)
.collect::<Vec<EncodableOwner>>();
let owners = Team::owning(&krate, &mut conn)
.await?
.into_iter()
.map(Owner::into)
.collect::<Vec<EncodableOwner>>();

Ok(Json(json!({ "teams": owners })))
})
.await
Ok(Json(json!({ "teams": owners })))
}

/// Handles the `GET /crates/:crate_id/owner_user` route.
Expand Down
8 changes: 5 additions & 3 deletions src/models/team.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use diesel_async::AsyncPgConnection;
use http::StatusCode;

use crate::app::App;
Expand Down Expand Up @@ -199,15 +200,16 @@ impl Team {
}
}

pub fn owning(krate: &Crate, conn: &mut impl Conn) -> QueryResult<Vec<Owner>> {
use diesel::RunQueryDsl;
pub async fn owning(krate: &Crate, conn: &mut AsyncPgConnection) -> QueryResult<Vec<Owner>> {
use diesel_async::RunQueryDsl;

let base_query = CrateOwner::belonging_to(krate).filter(crate_owners::deleted.eq(false));
let teams = base_query
.inner_join(teams::table)
.select(Team::as_select())
.filter(crate_owners::owner_kind.eq(OwnerKind::Team))
.load(conn)?
.load(conn)
.await?
.into_iter()
.map(Owner::Team);

Expand Down