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
6 changes: 5 additions & 1 deletion crates/crates_io_database/src/models/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub struct VersionOwnerAction {

impl VersionOwnerAction {
pub async fn all(conn: &mut AsyncPgConnection) -> QueryResult<Vec<Self>> {
version_owner_actions::table.load(conn).await
version_owner_actions::table
.select(Self::as_select())
.load(conn)
.await
}

pub fn by_version<'a>(
Expand Down Expand Up @@ -100,6 +103,7 @@ impl NewVersionOwnerAction {
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<VersionOwnerAction> {
diesel::insert_into(version_owner_actions::table)
.values(self)
.returning(VersionOwnerAction::as_select())
.get_result(conn)
.await
}
Expand Down
2 changes: 2 additions & 0 deletions crates/crates_io_database/src/models/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Category {
async move {
let categories: Vec<Category> = categories::table
.filter(categories::slug.eq_any(slugs))
.select(Category::as_select())
.load(conn)
.await?;

Expand Down Expand Up @@ -400,6 +401,7 @@ mod tests {
.unwrap();

let cat: Category = Category::by_slug("cat1::sub1")
.select(Category::as_select())
.first(&mut conn)
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl CloudFrontInvalidationQueueItem {
cloudfront_invalidation_queue::table
.order(cloudfront_invalidation_queue::created_at.asc())
.limit(limit)
.select(Self::as_select())
.load(conn)
.await
}
Expand Down
2 changes: 2 additions & 0 deletions crates/crates_io_database/src/models/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Keyword {
pub async fn find_by_keyword(conn: &mut AsyncPgConnection, name: &str) -> QueryResult<Keyword> {
keywords::table
.filter(keywords::keyword.eq(lower(name)))
.select(Keyword::as_select())
.first(conn)
.await
}
Expand All @@ -55,6 +56,7 @@ impl Keyword {

keywords::table
.filter(keywords::keyword.eq_any(&lowercase_names))
.select(Keyword::as_select())
.load(conn)
.await
}
Expand Down
1 change: 1 addition & 0 deletions crates/crates_io_database/src/models/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl NewTeam<'_> {
.on_conflict(teams::github_id)
.do_update()
.set(self)
.returning(Team::as_returning())
.get_result(conn)
.await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod tests {
// Retrieve the config
let retrieved_config = trustpub_configs_gitlab::table
.filter(trustpub_configs_gitlab::id.eq(inserted_config.id))
.select(GitLabConfig::as_select())
.first::<GitLabConfig>(&mut conn)
.await
.unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ pub async fn find_category(
) -> AppResult<Json<GetResponse>> {
let mut conn = state.db_read().await?;

let cat: Category = Category::by_slug(&slug).first(&mut conn).await?;
let cat: Category = Category::by_slug(&slug)
.select(Category::as_select())
.first(&mut conn)
.await?;
let (subcats, parents) = tokio::try_join!(
cat.subcategories(&mut conn),
cat.parent_categories(&mut conn).boxed(),
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ async fn prepare_list(
crate_owner_invitations::invited_user_id,
))
// We fetch one element over the page limit to then detect whether there is a next page.
.limit(pagination.per_page + 1);
.limit(pagination.per_page + 1)
.select(CrateOwnerInvitation::as_select());

// Load and paginate the results.
let mut raw_invitations: Vec<CrateOwnerInvitation> = match pagination.page {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn list_keywords(
) -> AppResult<Json<ListResponse>> {
use crate::schema::keywords;

let mut query = keywords::table.into_boxed();
let mut query = keywords::table.select(Keyword::as_select()).into_boxed();

query = match &params.sort {
Some(sort) if sort == "crates" => query.order(keywords::crates_cnt.desc()),
Expand Down
1 change: 1 addition & 0 deletions src/controllers/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub async fn get_summary(state: AppState) -> AppResult<Json<SummaryResponse>> {
keywords::table
.order(keywords::crates_cnt.desc())
.limit(10)
.select(Keyword::as_select())
.load(&mut conn)
.boxed(),
)?;
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ pub async fn find_team(state: AppState, Path(name): Path<String>) -> AppResult<J
use crate::schema::teams::dsl::{login, teams};

let mut conn = state.db_read().await?;
let team: Team = teams.filter(login.eq(&name)).first(&mut conn).await?;
let team: Team = teams
.filter(login.eq(&name))
.select(Team::as_select())
.first(&mut conn)
.await?;
let team = EncodableTeam::from(team);
Ok(Json(GetResponse { team }))
}
1 change: 1 addition & 0 deletions src/controllers/trustpub/tokens/exchange/gitlab_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ async fn test_lazy_namespace_id_population() -> anyhow::Result<()> {
let config: GitLabConfig = trustpub_configs_gitlab::table
.filter(trustpub_configs_gitlab::namespace.eq(NAMESPACE))
.filter(trustpub_configs_gitlab::project.eq(PROJECT))
.select(GitLabConfig::as_select())
.first(&mut conn)
.await?;

Expand Down
4 changes: 3 additions & 1 deletion src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl RateLimiter {
publish_limit_buckets::last_refill.eq(publish_limit_buckets::last_refill
+ refill_rate.into_sql::<Interval>() * tokens_to_add),
))
.returning(Bucket::as_select())
.get_result(conn)
.await
}
Expand All @@ -170,7 +171,7 @@ impl RateLimiter {
}
}

#[derive(Queryable, Insertable, Debug, PartialEq, Clone, Copy)]
#[derive(Queryable, Insertable, Selectable, Debug, PartialEq, Clone, Copy)]
#[diesel(table_name = publish_limit_buckets, check_for_backend(diesel::pg::Pg))]
#[allow(dead_code)] // Most fields only read in tests
struct Bucket {
Expand Down Expand Up @@ -725,6 +726,7 @@ mod tests {
last_refill: now,
action: LimitedAction::PublishNew,
})
.returning(Bucket::as_returning())
.get_result(conn)
.await
}
Expand Down