Testing bug fixes (#788)

* fixes

* adds tests- fixes failures

* changes

* moved transaction commits/caches around

* collections nullable

* merge fixes

* sqlx prepare

* revs

* lf fixes

* made changes back

* added collections update

---------

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Wyatt Verchere
2023-12-14 15:19:50 -07:00
committed by GitHub
parent 50e89ad98b
commit f939e59463
33 changed files with 494 additions and 112 deletions

View File

@@ -46,7 +46,7 @@ pub struct CollectionCreateData {
pub name: String,
#[validate(length(min = 3, max = 255))]
/// A short description of the collection.
pub description: String,
pub description: Option<String>,
#[validate(length(max = 32))]
#[serde(default = "Vec::new")]
/// A list of initial projects to use with the created collection
@@ -198,7 +198,12 @@ pub struct EditCollection {
)]
pub name: Option<String>,
#[validate(length(min = 3, max = 256))]
pub description: Option<String>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::double_option"
)]
pub description: Option<Option<String>>,
pub status: Option<CollectionStatus>,
#[validate(length(max = 64))]
pub new_projects: Option<Vec<String>>,
@@ -260,7 +265,7 @@ pub async fn collection_edit(
SET description = $1
WHERE (id = $2)
",
description,
description.as_ref(),
id as database::models::ids::CollectionId,
)
.execute(&mut *transaction)
@@ -328,11 +333,22 @@ pub async fn collection_edit(
)
.execute(&mut *transaction)
.await?;
sqlx::query!(
"
UPDATE collections
SET updated = NOW()
WHERE id = $1
",
collection_item.id as database::models::ids::CollectionId,
)
.execute(&mut *transaction)
.await?;
}
transaction.commit().await?;
database::models::Collection::clear_cache(collection_item.id, &redis).await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::NotFound)
@@ -417,9 +433,8 @@ pub async fn collection_icon_edit(
.execute(&mut *transaction)
.await?;
database::models::Collection::clear_cache(collection_item.id, &redis).await?;
transaction.commit().await?;
database::models::Collection::clear_cache(collection_item.id, &redis).await?;
Ok(HttpResponse::NoContent().body(""))
} else {
@@ -481,9 +496,8 @@ pub async fn delete_collection_icon(
.execute(&mut *transaction)
.await?;
database::models::Collection::clear_cache(collection_item.id, &redis).await?;
transaction.commit().await?;
database::models::Collection::clear_cache(collection_item.id, &redis).await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -519,9 +533,9 @@ pub async fn collection_delete(
let result =
database::models::Collection::remove(collection.id, &mut transaction, &redis).await?;
database::models::Collection::clear_cache(collection.id, &redis).await?;
transaction.commit().await?;
database::models::Collection::clear_cache(collection.id, &redis).await?;
if result.is_some() {
Ok(HttpResponse::NoContent().body(""))

View File

@@ -456,6 +456,7 @@ pub async fn organizations_edit(
.await?;
}
transaction.commit().await?;
database::models::Organization::clear_cache(
organization_item.id,
Some(organization_item.name),
@@ -463,7 +464,6 @@ pub async fn organizations_edit(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::CustomAuthentication(
@@ -819,6 +819,7 @@ pub async fn organization_icon_edit(
.execute(&mut *transaction)
.await?;
transaction.commit().await?;
database::models::Organization::clear_cache(
organization_item.id,
Some(organization_item.name),
@@ -826,8 +827,6 @@ pub async fn organization_icon_edit(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::InvalidInput(format!(
@@ -904,6 +903,8 @@ pub async fn delete_organization_icon(
.execute(&mut *transaction)
.await?;
transaction.commit().await?;
database::models::Organization::clear_cache(
organization_item.id,
Some(organization_item.name),
@@ -911,7 +912,5 @@ pub async fn delete_organization_icon(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
}

View File

@@ -144,12 +144,6 @@ pub async fn paypal_webhook(
.execute(&mut *transaction)
.await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&redis,
)
.await?;
sqlx::query!(
"
UPDATE payouts
@@ -168,6 +162,12 @@ pub async fn paypal_webhook(
.await?;
transaction.commit().await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&redis,
)
.await?;
}
}
"PAYMENT.PAYOUTS-ITEM.SUCCEEDED" => {
@@ -265,12 +265,6 @@ pub async fn tremendous_webhook(
.execute(&mut *transaction)
.await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&redis,
)
.await?;
sqlx::query!(
"
UPDATE payouts
@@ -289,6 +283,12 @@ pub async fn tremendous_webhook(
.await?;
transaction.commit().await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&redis,
)
.await?;
}
}
"REWARDS.DELIVERY.SUCCEEDED" => {
@@ -616,9 +616,9 @@ pub async fn create_payout(
.execute(&mut *transaction)
.await?;
payout_item.insert(&mut transaction).await?;
crate::database::models::User::clear_caches(&[(user.id, None)], &redis).await?;
transaction.commit().await?;
crate::database::models::User::clear_caches(&[(user.id, None)], &redis).await?;
Ok(HttpResponse::NoContent().finish())
}

View File

@@ -839,6 +839,8 @@ pub async fn project_edit(
};
img::delete_unused_images(context, checkable_strings, &mut transaction, &redis).await?;
transaction.commit().await?;
db_models::Project::clear_cache(
project_item.inner.id,
project_item.inner.slug,
@@ -847,7 +849,6 @@ pub async fn project_edit(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::CustomAuthentication(
@@ -1501,6 +1502,7 @@ pub async fn project_icon_edit(
.execute(&mut *transaction)
.await?;
transaction.commit().await?;
db_models::Project::clear_cache(
project_item.inner.id,
project_item.inner.slug,
@@ -1509,8 +1511,6 @@ pub async fn project_icon_edit(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::InvalidInput(format!(
@@ -1596,11 +1596,10 @@ pub async fn delete_project_icon(
.execute(&mut *transaction)
.await?;
transaction.commit().await?;
db_models::Project::clear_cache(project_item.inner.id, project_item.inner.slug, None, &redis)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -1736,6 +1735,7 @@ pub async fn add_gallery_item(
}];
GalleryItem::insert_many(gallery_item, project_item.inner.id, &mut transaction).await?;
transaction.commit().await?;
db_models::Project::clear_cache(
project_item.inner.id,
project_item.inner.slug,
@@ -1744,8 +1744,6 @@ pub async fn add_gallery_item(
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::InvalidInput(format!(
@@ -1921,11 +1919,11 @@ pub async fn edit_gallery_item(
.await?;
}
transaction.commit().await?;
db_models::Project::clear_cache(project_item.inner.id, project_item.inner.slug, None, &redis)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -2027,11 +2025,11 @@ pub async fn delete_gallery_item(
.execute(&mut *transaction)
.await?;
transaction.commit().await?;
db_models::Project::clear_cache(project_item.inner.id, project_item.inner.slug, None, &redis)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
}

View File

@@ -217,6 +217,7 @@ pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse,
#[derive(serde::Serialize, serde::Deserialize)]
pub struct LinkPlatformQueryData {
pub name: String,
pub donation: bool,
}
pub async fn link_platform_list(
@@ -226,7 +227,10 @@ pub async fn link_platform_list(
let results: Vec<LinkPlatformQueryData> = LinkPlatform::list(&**pool, &redis)
.await?
.into_iter()
.map(|x| LinkPlatformQueryData { name: x.name })
.map(|x| LinkPlatformQueryData {
name: x.name,
donation: x.donation,
})
.collect();
Ok(HttpResponse::Ok().json(results))
}

View File

@@ -348,10 +348,10 @@ pub async fn join_team(
)
.await?;
transaction.commit().await?;
User::clear_project_cache(&[current_user.id.into()], &redis).await?;
TeamMember::clear_cache(team_id, &redis).await?;
transaction.commit().await?;
} else {
return Err(ApiError::InvalidInput(
"There is no pending request from this team".to_string(),
@@ -542,9 +542,8 @@ pub async fn add_team_member(
}
}
TeamMember::clear_cache(team_id, &redis).await?;
transaction.commit().await?;
TeamMember::clear_cache(team_id, &redis).await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -691,9 +690,8 @@ pub async fn edit_team_member(
)
.await?;
TeamMember::clear_cache(id, &redis).await?;
transaction.commit().await?;
TeamMember::clear_cache(id, &redis).await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -797,9 +795,8 @@ pub async fn transfer_ownership(
)
.await?;
TeamMember::clear_cache(id.into(), &redis).await?;
transaction.commit().await?;
TeamMember::clear_cache(id.into(), &redis).await?;
Ok(HttpResponse::NoContent().body(""))
}
@@ -925,10 +922,11 @@ pub async fn remove_team_member(
}
}
transaction.commit().await?;
TeamMember::clear_cache(id, &redis).await?;
User::clear_project_cache(&[delete_member.user_id], &redis).await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::NotFound)

View File

@@ -449,8 +449,8 @@ pub async fn user_edit(
.await?;
}
User::clear_caches(&[(id, Some(actual_user.username))], &redis).await?;
transaction.commit().await?;
User::clear_caches(&[(id, Some(actual_user.username))], &redis).await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::CustomAuthentication(

View File

@@ -664,6 +664,7 @@ pub async fn version_edit_helper(
img::delete_unused_images(context, checkable_strings, &mut transaction, &redis).await?;
transaction.commit().await?;
database::models::Version::clear_cache(&version_item, &redis).await?;
database::models::Project::clear_cache(
version_item.inner.project_id,
@@ -672,7 +673,6 @@ pub async fn version_edit_helper(
&redis,
)
.await?;
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {
Err(ApiError::CustomAuthentication(
@@ -921,8 +921,8 @@ pub async fn version_schedule(
.execute(&mut *transaction)
.await?;
database::models::Version::clear_cache(&version_item, &redis).await?;
transaction.commit().await?;
database::models::Version::clear_cache(&version_item, &redis).await?;
Ok(HttpResponse::NoContent().body(""))
} else {
@@ -1004,12 +1004,11 @@ pub async fn version_delete(
let result =
database::models::Version::remove_full(version.inner.id, &redis, &mut transaction).await?;
transaction.commit().await?;
remove_documents(&[version.inner.id.into()], &search_config).await?;
database::models::Project::clear_cache(version.inner.project_id, None, Some(true), &redis)
.await?;
transaction.commit().await?;
if result.is_some() {
Ok(HttpResponse::NoContent().body(""))
} else {