You've already forked AstralRinth
forked from didirus/AstralRinth
fix version update route perf (#923)
* fix version update route perf * fix tests
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n SELECT v.id version_id, v.mod_id mod_id\n FROM versions v\n INNER JOIN version_fields vf ON vf.field_id = 3 AND v.id = vf.version_id\n INNER JOIN loader_field_enum_values lfev ON vf.enum_value = lfev.id AND (cardinality($2::varchar[]) = 0 OR lfev.value = ANY($2::varchar[]))\n INNER JOIN loaders_versions lv ON lv.version_id = v.id\n INNER JOIN loaders l on lv.loader_id = l.id AND (cardinality($3::varchar[]) = 0 OR l.loader = ANY($3::varchar[]))\n WHERE v.mod_id = ANY($1) AND (cardinality($4::varchar[]) = 0 OR v.version_type = ANY($4))\n ORDER BY v.date_published ASC\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "version_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "mod_id",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8Array",
|
|
||||||
"VarcharArray",
|
|
||||||
"VarcharArray",
|
|
||||||
"VarcharArray"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "070174adf972b808aca7519168719e6c7b762bfbcc09d8ab2624b00113f71e77"
|
|
||||||
}
|
|
||||||
31
.sqlx/query-26210e28d63aa61e6bea453b720bc18674c8f19334bdbeb48244a941f10a5e17.json
generated
Normal file
31
.sqlx/query-26210e28d63aa61e6bea453b720bc18674c8f19334bdbeb48244a941f10a5e17.json
generated
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n SELECT v.id version_id, v.mod_id mod_id\n FROM mods m\n INNER JOIN versions v ON m.id = v.mod_id AND (cardinality($4::varchar[]) = 0 OR v.version_type = ANY($4))\n INNER JOIN version_fields vf ON vf.field_id = 3 AND v.id = vf.version_id\n INNER JOIN loader_field_enum_values lfev ON vf.enum_value = lfev.id AND (cardinality($2::varchar[]) = 0 OR lfev.value = ANY($2::varchar[]))\n INNER JOIN loaders_versions lv ON lv.version_id = v.id\n INNER JOIN loaders l on lv.loader_id = l.id AND (cardinality($3::varchar[]) = 0 OR l.loader = ANY($3::varchar[]))\n WHERE m.id = ANY($1)\n ORDER BY v.date_published ASC\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "version_id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "mod_id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8Array",
|
||||||
|
"VarcharArray",
|
||||||
|
"VarcharArray",
|
||||||
|
"VarcharArray"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "26210e28d63aa61e6bea453b720bc18674c8f19334bdbeb48244a941f10a5e17"
|
||||||
|
}
|
||||||
@@ -469,7 +469,7 @@ impl User {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for collection_id in user_collections {
|
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!(
|
let report_threads = sqlx::query!(
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ impl AutomatedModerationQueue {
|
|||||||
for file in
|
for file in
|
||||||
files.iter().filter(|x| x.version_id == version.id.into())
|
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
|
if let Some((index, (sha1, _, file_name, _))) = hashes
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|||||||
@@ -249,12 +249,6 @@ pub struct OAuthClientEdit {
|
|||||||
)]
|
)]
|
||||||
pub name: Option<String>,
|
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>,
|
pub max_scopes: Option<Scopes>,
|
||||||
|
|
||||||
#[validate(length(min = 1))]
|
#[validate(length(min = 1))]
|
||||||
@@ -293,20 +287,12 @@ pub async fn oauth_client_edit(
|
|||||||
.validate()
|
.validate()
|
||||||
.map_err(|e| ApiError::Validation(validation_errors_to_string(e, None)))?;
|
.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? {
|
if let Some(existing_client) = OAuthClient::get(client_id.into_inner().into(), &**pool).await? {
|
||||||
existing_client.validate_authorized(Some(¤t_user))?;
|
existing_client.validate_authorized(Some(¤t_user))?;
|
||||||
|
|
||||||
let mut updated_client = existing_client.clone();
|
let mut updated_client = existing_client.clone();
|
||||||
let OAuthClientEdit {
|
let OAuthClientEdit {
|
||||||
name,
|
name,
|
||||||
icon_url,
|
|
||||||
max_scopes,
|
max_scopes,
|
||||||
redirect_uris,
|
redirect_uris,
|
||||||
url,
|
url,
|
||||||
@@ -316,10 +302,6 @@ pub async fn oauth_client_edit(
|
|||||||
updated_client.name = name;
|
updated_client.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(icon_url) = icon_url {
|
|
||||||
updated_client.icon_url = icon_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(max_scopes) = max_scopes {
|
if let Some(max_scopes) = max_scopes {
|
||||||
updated_client.max_scopes = max_scopes;
|
updated_client.max_scopes = max_scopes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,12 +331,13 @@ pub async fn update_files(
|
|||||||
let update_version_ids = sqlx::query!(
|
let update_version_ids = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT v.id version_id, v.mod_id mod_id
|
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 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 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_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[]))
|
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
|
ORDER BY v.date_published ASC
|
||||||
",
|
",
|
||||||
&files.iter().map(|x| x.project_id.0).collect::<Vec<_>>(),
|
&files.iter().map(|x| x.project_id.0).collect::<Vec<_>>(),
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ impl super::Validator for ModpackValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for file in &pack.files {
|
for file in &pack.files {
|
||||||
if file.hashes.get(&PackFileHash::Sha1).is_none() {
|
if !file.hashes.contains_key(&PackFileHash::Sha1) {
|
||||||
return Err(ValidationError::InvalidInput(
|
return Err(ValidationError::InvalidInput(
|
||||||
"All pack files must provide a SHA1 hash!".into(),
|
"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(
|
return Err(ValidationError::InvalidInput(
|
||||||
"All pack files must provide a SHA512 hash!".into(),
|
"All pack files must provide a SHA512 hash!".into(),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ async fn can_create_edit_get_oauth_client() {
|
|||||||
let creation_result: OAuthClientCreationResult = test::read_body_json(resp).await;
|
let creation_result: OAuthClientCreationResult = test::read_body_json(resp).await;
|
||||||
let client_id = get_json_val_str(creation_result.client.id);
|
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 url = Some("https://modrinth.com".to_string());
|
||||||
let description = Some("test description".to_string());
|
let description = Some("test description".to_string());
|
||||||
let edited_redirect_uris = vec![
|
let edited_redirect_uris = vec![
|
||||||
@@ -49,7 +48,6 @@ async fn can_create_edit_get_oauth_client() {
|
|||||||
];
|
];
|
||||||
let edit = OAuthClientEdit {
|
let edit = OAuthClientEdit {
|
||||||
name: None,
|
name: None,
|
||||||
icon_url: Some(icon_url.clone()),
|
|
||||||
max_scopes: None,
|
max_scopes: None,
|
||||||
redirect_uris: Some(edited_redirect_uris.clone()),
|
redirect_uris: Some(edited_redirect_uris.clone()),
|
||||||
url: Some(url.clone()),
|
url: Some(url.clone()),
|
||||||
@@ -66,7 +64,6 @@ async fn can_create_edit_get_oauth_client() {
|
|||||||
.get_user_oauth_clients(FRIEND_USER_ID, FRIEND_USER_PAT)
|
.get_user_oauth_clients(FRIEND_USER_ID, FRIEND_USER_PAT)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(1, clients.len());
|
assert_eq!(1, clients.len());
|
||||||
assert_eq!(icon_url, clients[0].icon_url);
|
|
||||||
assert_eq!(url, clients[0].url);
|
assert_eq!(url, clients[0].url);
|
||||||
assert_eq!(description, clients[0].description);
|
assert_eq!(description, clients[0].description);
|
||||||
assert_eq!(client_name, clients[0].name);
|
assert_eq!(client_name, clients[0].name);
|
||||||
|
|||||||
Reference in New Issue
Block a user