You've already forked AstralRinth
forked from didirus/AstralRinth
gv loader cache bring back (#677)
* gv loader cache bring back * run prep fmt
This commit is contained in:
@@ -154,6 +154,8 @@ impl ProjectBuilder {
|
||||
webhook_sent: false,
|
||||
color: self.color,
|
||||
monetization_status: self.monetization_status,
|
||||
loaders: vec![],
|
||||
game_versions: vec![],
|
||||
};
|
||||
project_struct.insert(&mut *transaction).await?;
|
||||
|
||||
@@ -196,6 +198,9 @@ impl ProjectBuilder {
|
||||
.await?;
|
||||
}
|
||||
|
||||
Project::update_game_versions(self.project_id, &mut *transaction).await?;
|
||||
Project::update_loaders(self.project_id, &mut *transaction).await?;
|
||||
|
||||
Ok(self.project_id)
|
||||
}
|
||||
}
|
||||
@@ -231,6 +236,8 @@ pub struct Project {
|
||||
pub webhook_sent: bool,
|
||||
pub color: Option<u32>,
|
||||
pub monetization_status: MonetizationStatus,
|
||||
pub loaders: Vec<String>,
|
||||
pub game_versions: Vec<String>,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
@@ -547,9 +554,7 @@ impl Project {
|
||||
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.webhook_sent, m.color,
|
||||
t.id thread_id, m.monetization_status monetization_status,
|
||||
ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,
|
||||
JSONB_AGG(DISTINCT jsonb_build_object('id', gv.version, 'created', gv.created)) filter (where gv.version is not null) game_versions,
|
||||
t.id thread_id, m.monetization_status monetization_status, 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,
|
||||
@@ -566,10 +571,6 @@ impl Project {
|
||||
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($3)
|
||||
LEFT JOIN loaders_versions lv ON v.id = lv.version_id
|
||||
LEFT JOIN loaders l ON lv.loader_id = l.id
|
||||
LEFT JOIN game_versions_versions gvv ON v.id = gvv.joining_version_id
|
||||
LEFT JOIN game_versions gv ON gvv.game_version_id = gv.id
|
||||
WHERE m.id = ANY($1) OR m.slug = ANY($2)
|
||||
GROUP BY pt.id, cs.id, ss.id, t.id, m.id;
|
||||
",
|
||||
@@ -620,6 +621,8 @@ impl Project {
|
||||
monetization_status: MonetizationStatus::from_str(
|
||||
&m.monetization_status,
|
||||
),
|
||||
loaders: m.loaders,
|
||||
game_versions: m.game_versions,
|
||||
},
|
||||
project_type: m.project_type_name,
|
||||
categories: m.categories.unwrap_or_default(),
|
||||
@@ -655,25 +658,7 @@ impl Project {
|
||||
).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),
|
||||
loaders: m.loaders.unwrap_or_default(),
|
||||
game_versions: {
|
||||
#[derive(Deserialize)]
|
||||
struct GameVersion {
|
||||
pub id: String,
|
||||
pub created: DateTime<Utc>,
|
||||
}
|
||||
|
||||
let mut game_versions: Vec<GameVersion> = serde_json::from_value(
|
||||
m.game_versions.unwrap_or_default(),
|
||||
)
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
|
||||
game_versions.sort_by(|a, b| a.created.cmp(&b.created));
|
||||
|
||||
game_versions.into_iter().map(|x| x.id).collect()
|
||||
},
|
||||
thread_id: ThreadId(m.thread_id),
|
||||
thread_id: ThreadId(m.thread_id),
|
||||
}}))
|
||||
})
|
||||
.try_collect::<Vec<QueryProject>>()
|
||||
@@ -771,6 +756,56 @@ impl Project {
|
||||
Ok(dependencies)
|
||||
}
|
||||
|
||||
pub async fn update_game_versions(
|
||||
id: ProjectId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), sqlx::error::Error> {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET game_versions = (
|
||||
SELECT COALESCE(ARRAY_AGG(DISTINCT gv.version) filter (where gv.version is not null), array[]::varchar[])
|
||||
FROM versions v
|
||||
INNER JOIN game_versions_versions gvv ON v.id = gvv.joining_version_id
|
||||
INNER JOIN game_versions gv on gvv.game_version_id = gv.id
|
||||
WHERE v.mod_id = mods.id AND v.status != ALL($2)
|
||||
)
|
||||
WHERE id = $1
|
||||
",
|
||||
id as ProjectId,
|
||||
&*crate::models::projects::VersionStatus::iterator().filter(|x| x.is_hidden()).map(|x| x.to_string()).collect::<Vec<String>>()
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_loaders(
|
||||
id: ProjectId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), sqlx::error::Error> {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET loaders = (
|
||||
SELECT COALESCE(ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null), array[]::varchar[])
|
||||
FROM versions v
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = v.id
|
||||
INNER JOIN loaders l on lv.loader_id = l.id
|
||||
WHERE v.mod_id = mods.id AND v.status != ALL($2)
|
||||
)
|
||||
WHERE id = $1
|
||||
",
|
||||
id as ProjectId,
|
||||
&*crate::models::projects::VersionStatus::iterator().filter(|x| x.is_hidden()).map(|x| x.to_string()).collect::<Vec<String>>()
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn clear_cache(
|
||||
id: ProjectId,
|
||||
slug: Option<String>,
|
||||
@@ -809,7 +844,5 @@ pub struct QueryProject {
|
||||
pub gallery_items: Vec<GalleryItem>,
|
||||
pub client_side: crate::models::projects::SideType,
|
||||
pub server_side: crate::models::projects::SideType,
|
||||
pub loaders: Vec<String>,
|
||||
pub game_versions: Vec<String>,
|
||||
pub thread_id: ThreadId,
|
||||
}
|
||||
|
||||
@@ -381,6 +381,17 @@ impl Version {
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
crate::database::models::Project::update_game_versions(
|
||||
ProjectId(project_id.mod_id),
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
crate::database::models::Project::update_loaders(
|
||||
ProjectId(project_id.mod_id),
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Some(()))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user