fix version update route perf (#923)

* fix version update route perf

* fix tests
This commit is contained in:
Geometrically
2024-06-12 09:58:01 -07:00
committed by GitHub
parent b933202694
commit 872ffa02ce
8 changed files with 38 additions and 58 deletions

View File

@@ -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!(

View File

@@ -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()

View File

@@ -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))]
@@ -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,
@@ -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;
}

View File

@@ -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<_>>(),

View File

@@ -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(),
));