You've already forked AstralRinth
forked from didirus/AstralRinth
Staging bug fixes (#819)
* Staging bug fixes * Finish fixes * fix tests * Update migration * Update migrations * fix side types being added for ineligible loaders * fix tests * Fix tests * Finish fixes * Add slug display names
This commit is contained in:
@@ -15,7 +15,10 @@ pub struct Organization {
|
||||
/// The id of the organization
|
||||
pub id: OrganizationId,
|
||||
|
||||
/// The title (and slug) of the organization
|
||||
/// The slug of the organization
|
||||
pub slug: String,
|
||||
|
||||
/// The title of the organization
|
||||
pub name: String,
|
||||
|
||||
/// The associated team of the organization
|
||||
@@ -36,10 +39,11 @@ impl Organization {
|
||||
) -> Result<(), super::DatabaseError> {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO organizations (id, name, team_id, description, icon_url, color)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
INSERT INTO organizations (id, slug, name, team_id, description, icon_url, color)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
",
|
||||
self.id.0,
|
||||
self.slug,
|
||||
self.name,
|
||||
self.team_id as TeamId,
|
||||
self.description,
|
||||
@@ -149,7 +153,7 @@ impl Organization {
|
||||
{
|
||||
remaining_strings.retain(|x| {
|
||||
&to_base62(organization.id.0 as u64) != x
|
||||
&& organization.name.to_lowercase() != x.to_lowercase()
|
||||
&& organization.slug.to_lowercase() != x.to_lowercase()
|
||||
});
|
||||
found_organizations.push(organization);
|
||||
continue;
|
||||
@@ -166,9 +170,9 @@ impl Organization {
|
||||
|
||||
let organizations: Vec<Organization> = sqlx::query!(
|
||||
"
|
||||
SELECT o.id, o.name, o.team_id, o.description, o.icon_url, o.color
|
||||
SELECT o.id, o.slug, o.name, o.team_id, o.description, o.icon_url, o.color
|
||||
FROM organizations o
|
||||
WHERE o.id = ANY($1) OR LOWER(o.name) = ANY($2)
|
||||
WHERE o.id = ANY($1) OR LOWER(o.slug) = ANY($2)
|
||||
GROUP BY o.id;
|
||||
",
|
||||
&organization_ids_parsed,
|
||||
@@ -181,6 +185,7 @@ impl Organization {
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|m| Organization {
|
||||
id: OrganizationId(m.id),
|
||||
slug: m.slug,
|
||||
name: m.name,
|
||||
team_id: TeamId(m.team_id),
|
||||
description: m.description,
|
||||
@@ -203,7 +208,7 @@ impl Organization {
|
||||
redis
|
||||
.set(
|
||||
ORGANIZATIONS_TITLES_NAMESPACE,
|
||||
&organization.name.to_lowercase(),
|
||||
&organization.slug.to_lowercase(),
|
||||
&organization.id.0.to_string(),
|
||||
None,
|
||||
)
|
||||
@@ -226,7 +231,7 @@ impl Organization {
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT o.id, o.name, o.team_id, o.description, o.icon_url, o.color
|
||||
SELECT o.id, o.slug, o.name, o.team_id, o.description, o.icon_url, o.color
|
||||
FROM organizations o
|
||||
LEFT JOIN mods m ON m.organization_id = o.id
|
||||
WHERE m.id = $1
|
||||
@@ -240,6 +245,7 @@ impl Organization {
|
||||
if let Some(result) = result {
|
||||
Ok(Some(Organization {
|
||||
id: OrganizationId(result.id),
|
||||
slug: result.slug,
|
||||
name: result.name,
|
||||
team_id: TeamId(result.team_id),
|
||||
description: result.description,
|
||||
@@ -299,7 +305,7 @@ impl Organization {
|
||||
|
||||
pub async fn clear_cache(
|
||||
id: OrganizationId,
|
||||
title: Option<String>,
|
||||
slug: Option<String>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), super::DatabaseError> {
|
||||
let mut redis = redis.connect().await?;
|
||||
@@ -309,7 +315,7 @@ impl Organization {
|
||||
(ORGANIZATIONS_NAMESPACE, Some(id.0.to_string())),
|
||||
(
|
||||
ORGANIZATIONS_TITLES_NAMESPACE,
|
||||
title.map(|x| x.to_lowercase()),
|
||||
slug.map(|x| x.to_lowercase()),
|
||||
),
|
||||
])
|
||||
.await?;
|
||||
|
||||
@@ -273,13 +273,13 @@ impl Project {
|
||||
id, team_id, name, summary, description,
|
||||
published, downloads, icon_url, status, requested_status,
|
||||
license_url, license,
|
||||
slug, color, monetization_status
|
||||
slug, color, monetization_status, organization_id
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5, $6,
|
||||
$7, $8, $9, $10,
|
||||
$11, $12,
|
||||
LOWER($13), $14, $15
|
||||
LOWER($13), $14, $15, $16
|
||||
)
|
||||
",
|
||||
self.id as ProjectId,
|
||||
@@ -297,6 +297,7 @@ impl Project {
|
||||
self.slug.as_ref(),
|
||||
self.color.map(|x| x as i32),
|
||||
self.monetization_status.as_str(),
|
||||
self.organization_id.map(|x| x.0 as i64),
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
@@ -412,10 +412,10 @@ impl TeamMember {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO team_members (
|
||||
id, team_id, user_id, role, permissions, organization_permissions, is_owner, accepted
|
||||
id, team_id, user_id, role, permissions, organization_permissions, is_owner, accepted, payouts_split
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8
|
||||
$1, $2, $3, $4, $5, $6, $7, $8, $9
|
||||
)
|
||||
",
|
||||
self.id as TeamMemberId,
|
||||
@@ -426,6 +426,7 @@ impl TeamMember {
|
||||
self.organization_permissions.map(|p| p.bits() as i64),
|
||||
self.is_owner,
|
||||
self.accepted,
|
||||
self.payouts_split
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
@@ -126,70 +126,42 @@ pub struct VersionFileBuilder {
|
||||
}
|
||||
|
||||
impl VersionFileBuilder {
|
||||
pub async fn insert_many(
|
||||
version_files: Vec<Self>,
|
||||
pub async fn insert(
|
||||
self,
|
||||
version_id: VersionId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<FileId, DatabaseError> {
|
||||
let file_id = generate_file_id(transaction).await?;
|
||||
let file_id = generate_file_id(&mut *transaction).await?;
|
||||
|
||||
let (file_ids, version_ids, urls, filenames, primary, sizes, file_types): (
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
Vec<_>,
|
||||
) = version_files
|
||||
.iter()
|
||||
.map(|f| {
|
||||
(
|
||||
file_id.0,
|
||||
version_id.0,
|
||||
f.url.clone(),
|
||||
f.filename.clone(),
|
||||
f.primary,
|
||||
f.size as i32,
|
||||
f.file_type.map(|x| x.to_string()),
|
||||
)
|
||||
})
|
||||
.multiunzip();
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO files (id, version_id, url, filename, is_primary, size, file_type)
|
||||
SELECT * FROM UNNEST($1::bigint[], $2::bigint[], $3::varchar[], $4::varchar[], $5::bool[], $6::integer[], $7::varchar[])
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
",
|
||||
&file_ids[..],
|
||||
&version_ids[..],
|
||||
&urls[..],
|
||||
&filenames[..],
|
||||
&primary[..],
|
||||
&sizes[..],
|
||||
&file_types[..] as &[Option<String>],
|
||||
file_id as FileId,
|
||||
version_id as VersionId,
|
||||
self.url,
|
||||
self.filename,
|
||||
self.primary,
|
||||
self.size as i32,
|
||||
self.file_type.map(|x| x.as_str()),
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
let (file_ids, algorithms, hashes): (Vec<_>, Vec<_>, Vec<_>) = version_files
|
||||
.into_iter()
|
||||
.flat_map(|f| {
|
||||
f.hashes
|
||||
.into_iter()
|
||||
.map(|h| (file_id.0, h.algorithm, h.hash))
|
||||
})
|
||||
.multiunzip();
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO hashes (file_id, algorithm, hash)
|
||||
SELECT * FROM UNNEST($1::bigint[], $2::varchar[], $3::bytea[])
|
||||
",
|
||||
&file_ids[..],
|
||||
&algorithms[..],
|
||||
&hashes[..],
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
for hash in self.hashes {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO hashes (file_id, algorithm, hash)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
file_id as FileId,
|
||||
hash.algorithm,
|
||||
hash.hash,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(file_id)
|
||||
}
|
||||
@@ -242,7 +214,10 @@ impl VersionBuilder {
|
||||
version_id,
|
||||
..
|
||||
} = self;
|
||||
VersionFileBuilder::insert_many(files, self.version_id, transaction).await?;
|
||||
|
||||
for file in files {
|
||||
file.insert(version_id, transaction).await?;
|
||||
}
|
||||
|
||||
DependencyBuilder::insert_many(dependencies, self.version_id, transaction).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user