Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix version update route perf (#923)
Browse files Browse the repository at this point in the history
* fix version update route perf

* fix tests
  • Loading branch information
Geometrically authored Jun 12, 2024
1 parent b933202 commit 872ffa0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 58 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/database/models/user_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl User {
.await?;

for collection_id in user_collections {
models::Collection::remove(collection_id, transaction, &redis).await?;
models::Collection::remove(collection_id, transaction, redis).await?;
}

let report_threads = sqlx::query!(
Expand Down
2 changes: 1 addition & 1 deletion src/queue/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl AutomatedModerationQueue {
for file in
files.iter().filter(|x| x.version_id == version.id.into())
{
if let Some(hash) = file.hashes.get(&"sha1".to_string()) {
if let Some(hash) = file.hashes.get("sha1") {
if let Some((index, (sha1, _, file_name, _))) = hashes
.iter()
.enumerate()
Expand Down
18 changes: 0 additions & 18 deletions src/routes/v3/oauth_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@ pub struct OAuthClientEdit {
)]
pub name: Option<String>,

#[validate(
custom(function = "crate::util::validate::validate_url"),
length(max = 255)
)]
pub icon_url: Option<Option<String>>,

pub max_scopes: Option<Scopes>,

#[validate(length(min = 1))]
Expand Down Expand Up @@ -293,20 +287,12 @@ pub async fn oauth_client_edit(
.validate()
.map_err(|e| ApiError::Validation(validation_errors_to_string(e, None)))?;

if client_updates.icon_url.is_none()
&& client_updates.name.is_none()
&& client_updates.max_scopes.is_none()
{
return Err(ApiError::InvalidInput("No changes provided".to_string()));
}

if let Some(existing_client) = OAuthClient::get(client_id.into_inner().into(), &**pool).await? {
existing_client.validate_authorized(Some(&current_user))?;

let mut updated_client = existing_client.clone();
let OAuthClientEdit {
name,
icon_url,
max_scopes,
redirect_uris,
url,
Expand All @@ -316,10 +302,6 @@ pub async fn oauth_client_edit(
updated_client.name = name;
}

if let Some(icon_url) = icon_url {
updated_client.icon_url = icon_url;
}

if let Some(max_scopes) = max_scopes {
updated_client.max_scopes = max_scopes;
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/v3/version_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,13 @@ pub async fn update_files(
let update_version_ids = sqlx::query!(
"
SELECT v.id version_id, v.mod_id mod_id
FROM versions v
FROM mods m
INNER JOIN versions v ON m.id = v.mod_id AND (cardinality($4::varchar[]) = 0 OR v.version_type = ANY($4))
INNER JOIN version_fields vf ON vf.field_id = 3 AND v.id = vf.version_id
INNER JOIN loader_field_enum_values lfev ON vf.enum_value = lfev.id AND (cardinality($2::varchar[]) = 0 OR lfev.value = ANY($2::varchar[]))
INNER JOIN loaders_versions lv ON lv.version_id = v.id
INNER JOIN loaders l on lv.loader_id = l.id AND (cardinality($3::varchar[]) = 0 OR l.loader = ANY($3::varchar[]))
WHERE v.mod_id = ANY($1) AND (cardinality($4::varchar[]) = 0 OR v.version_type = ANY($4))
WHERE m.id = ANY($1)
ORDER BY v.date_published ASC
",
&files.iter().map(|x| x.project_id.0).collect::<Vec<_>>(),
Expand Down
4 changes: 2 additions & 2 deletions src/validate/modpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl super::Validator for ModpackValidator {
}

for file in &pack.files {
if file.hashes.get(&PackFileHash::Sha1).is_none() {
if !file.hashes.contains_key(&PackFileHash::Sha1) {
return Err(ValidationError::InvalidInput(
"All pack files must provide a SHA1 hash!".into(),
));
}

if file.hashes.get(&PackFileHash::Sha512).is_none() {
if !file.hashes.contains_key(&PackFileHash::Sha512) {
return Err(ValidationError::InvalidInput(
"All pack files must provide a SHA512 hash!".into(),
));
Expand Down
3 changes: 0 additions & 3 deletions tests/oauth_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async fn can_create_edit_get_oauth_client() {
let creation_result: OAuthClientCreationResult = test::read_body_json(resp).await;
let client_id = get_json_val_str(creation_result.client.id);

let icon_url = Some("https://modrinth.com/icon".to_string());
let url = Some("https://modrinth.com".to_string());
let description = Some("test description".to_string());
let edited_redirect_uris = vec![
Expand All @@ -49,7 +48,6 @@ async fn can_create_edit_get_oauth_client() {
];
let edit = OAuthClientEdit {
name: None,
icon_url: Some(icon_url.clone()),
max_scopes: None,
redirect_uris: Some(edited_redirect_uris.clone()),
url: Some(url.clone()),
Expand All @@ -66,7 +64,6 @@ async fn can_create_edit_get_oauth_client() {
.get_user_oauth_clients(FRIEND_USER_ID, FRIEND_USER_PAT)
.await;
assert_eq!(1, clients.len());
assert_eq!(icon_url, clients[0].icon_url);
assert_eq!(url, clients[0].url);
assert_eq!(description, clients[0].description);
assert_eq!(client_name, clients[0].name);
Expand Down

0 comments on commit 872ffa0

Please sign in to comment.