Queue Dates + Warnings, some cleanup (#549)

* Queue Dates + Warnings, some cleanup

* Fix ping

* Fix repeated discord messaging

* Fix compile error + run fmt
This commit is contained in:
Geometrically
2023-03-14 14:48:46 -07:00
committed by GitHub
parent 150329dd4a
commit 630a71c46c
23 changed files with 701 additions and 2212 deletions

View File

@@ -119,6 +119,11 @@ impl ProjectBuilder {
published: Utc::now(),
updated: Utc::now(),
approved: None,
queued: if self.status == ProjectStatus::Processing {
Some(Utc::now())
} else {
None
},
status: self.status,
requested_status: self.requested_status,
downloads: 0,
@@ -202,6 +207,7 @@ pub struct Project {
pub published: DateTime<Utc>,
pub updated: DateTime<Utc>,
pub approved: Option<DateTime<Utc>>,
pub queued: Option<DateTime<Utc>>,
pub status: ProjectStatus,
pub requested_status: Option<ProjectStatus>,
pub downloads: i32,
@@ -281,69 +287,15 @@ impl Project {
executor: E,
) -> Result<Option<Self>, sqlx::error::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
let result = sqlx::query!(
"
SELECT project_type, title, description, downloads, follows,
icon_url, body, published,
updated, approved, status, requested_status,
issues_url, source_url, wiki_url, discord_url, license_url,
team_id, client_side, server_side, license, slug,
moderation_message, moderation_message_body, flame_anvil_project,
flame_anvil_user, webhook_sent, color, loaders, game_versions
FROM mods
WHERE id = $1
",
id as ProjectId,
)
.fetch_optional(executor)
.await?;
if let Some(row) = result {
Ok(Some(Project {
id,
project_type: ProjectTypeId(row.project_type),
team_id: TeamId(row.team_id),
title: row.title,
description: row.description,
downloads: row.downloads,
body_url: None,
icon_url: row.icon_url,
published: row.published,
updated: row.updated,
issues_url: row.issues_url,
source_url: row.source_url,
wiki_url: row.wiki_url,
license_url: row.license_url,
discord_url: row.discord_url,
client_side: SideTypeId(row.client_side),
status: ProjectStatus::from_str(&row.status),
requested_status: row
.requested_status
.map(|x| ProjectStatus::from_str(&x)),
server_side: SideTypeId(row.server_side),
license: row.license,
slug: row.slug,
body: row.body,
follows: row.follows,
moderation_message: row.moderation_message,
moderation_message_body: row.moderation_message_body,
approved: row.approved,
flame_anvil_project: row.flame_anvil_project,
flame_anvil_user: row.flame_anvil_user.map(UserId),
webhook_sent: row.webhook_sent,
color: row.color.map(|x| x as u32),
loaders: row.loaders,
game_versions: row.game_versions,
}))
} else {
Ok(None)
}
Project::get_many(&[id], executor)
.await
.map(|x| x.into_iter().next())
}
pub async fn get_many<'a, E>(
project_ids: Vec<ProjectId>,
project_ids: &[ProjectId],
exec: E,
) -> Result<Vec<Project>, sqlx::Error>
where
@@ -352,12 +304,12 @@ impl Project {
use futures::stream::TryStreamExt;
let project_ids_parsed: Vec<i64> =
project_ids.into_iter().map(|x| x.0).collect();
project_ids.iter().map(|x| x.0).collect();
let projects = sqlx::query!(
"
SELECT id, project_type, title, description, downloads, follows,
icon_url, body, published,
updated, approved, status, requested_status,
updated, approved, queued, status, requested_status,
issues_url, source_url, wiki_url, discord_url, license_url,
team_id, client_side, server_side, license, slug,
moderation_message, moderation_message_body, flame_anvil_project,
@@ -406,6 +358,7 @@ impl Project {
color: m.color.map(|x| x as u32),
loaders: m.loaders,
game_versions: m.game_versions,
queued: m.queued,
}))
})
.try_collect::<Vec<Project>>()
@@ -677,125 +630,9 @@ impl Project {
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT m.id id, m.project_type project_type, m.title title, m.description description, m.downloads downloads, m.follows follows,
m.icon_url icon_url, m.body body, m.published published,
m.updated updated, m.approved approved, m.status status, m.requested_status requested_status,
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
cs.name client_side_type, ss.name server_side_type, pt.name project_type_name, m.flame_anvil_project flame_anvil_project, m.flame_anvil_user flame_anvil_user, m.webhook_sent webhook_sent, m.color,
m.loaders loaders, m.game_versions game_versions,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url)) filter (where md.joining_platform_id is not null) donations
FROM mods m
INNER JOIN project_types pt ON pt.id = m.project_type
INNER JOIN side_types cs ON m.client_side = cs.id
INNER JOIN side_types ss ON m.server_side = ss.id
LEFT JOIN mods_donations md ON md.joining_mod_id = m.id
LEFT JOIN donation_platforms dp ON md.joining_platform_id = dp.id
LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id
LEFT JOIN categories c ON mc.joining_category_id = c.id
LEFT JOIN versions v ON v.mod_id = m.id AND v.status = ANY($2)
LEFT JOIN mods_gallery mg ON mg.mod_id = m.id
WHERE m.id = $1
GROUP BY pt.id, cs.id, ss.id, m.id;
",
id as ProjectId,
&*crate::models::projects::VersionStatus::iterator().filter(|x| x.is_listed()).map(|x| x.to_string()).collect::<Vec<String>>()
)
.fetch_optional(executor)
.await?;
if let Some(m) = result {
Ok(Some(QueryProject {
inner: Project {
id: ProjectId(m.id),
project_type: ProjectTypeId(m.project_type),
team_id: TeamId(m.team_id),
title: m.title.clone(),
description: m.description.clone(),
downloads: m.downloads,
body_url: None,
icon_url: m.icon_url.clone(),
published: m.published,
updated: m.updated,
issues_url: m.issues_url.clone(),
source_url: m.source_url.clone(),
wiki_url: m.wiki_url.clone(),
license_url: m.license_url.clone(),
discord_url: m.discord_url.clone(),
client_side: SideTypeId(m.client_side),
status: ProjectStatus::from_str(&m.status),
requested_status: m
.requested_status
.map(|x| ProjectStatus::from_str(&x)),
server_side: SideTypeId(m.server_side),
license: m.license.clone(),
slug: m.slug.clone(),
body: m.body.clone(),
follows: m.follows,
moderation_message: m.moderation_message,
moderation_message_body: m.moderation_message_body,
approved: m.approved,
flame_anvil_project: m.flame_anvil_project,
flame_anvil_user: m.flame_anvil_user.map(UserId),
webhook_sent: m.webhook_sent,
color: m.color.map(|x| x as u32),
loaders: m.loaders,
game_versions: m.game_versions,
},
project_type: m.project_type_name,
categories: m.categories.unwrap_or_default(),
additional_categories: m
.additional_categories
.unwrap_or_default(),
versions: {
#[derive(Deserialize)]
struct Version {
pub id: VersionId,
pub date_published: DateTime<Utc>,
}
let mut versions: Vec<Version> =
serde_json::from_value(m.versions.unwrap_or_default())
.ok()
.unwrap_or_default();
versions.sort_by(|a, b| {
a.date_published.cmp(&b.date_published)
});
versions.into_iter().map(|x| x.id).collect()
},
gallery_items: {
let mut gallery: Vec<GalleryItem> =
serde_json::from_value(m.gallery.unwrap_or_default())
.ok()
.unwrap_or_default();
gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering));
gallery
},
donation_urls: serde_json::from_value(
m.donations.unwrap_or_default(),
)
.ok()
.unwrap_or_default(),
client_side: crate::models::projects::SideType::from_str(
&m.client_side_type,
),
server_side: crate::models::projects::SideType::from_str(
&m.server_side_type,
),
}))
} else {
Ok(None)
}
Project::get_many_full(&[id], executor)
.await
.map(|x| x.into_iter().next())
}
pub async fn get_many_full<'a, E>(
@@ -813,7 +650,7 @@ impl Project {
"
SELECT m.id id, m.project_type project_type, m.title title, m.description description, m.downloads downloads, m.follows follows,
m.icon_url icon_url, m.body body, m.published published,
m.updated updated, m.approved approved, m.status status, m.requested_status requested_status,
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
cs.name client_side_type, ss.name server_side_type, pt.name project_type_name, m.flame_anvil_project flame_anvil_project, m.flame_anvil_user flame_anvil_user, m.webhook_sent, m.color,
@@ -882,6 +719,7 @@ impl Project {
color: m.color.map(|x| x as u32),
loaders: m.loaders,
game_versions: m.game_versions,
queued: m.queued,
},
project_type: m.project_type_name,
categories: m.categories.unwrap_or_default(),