forked from didirus/AstralRinth
Fixes incorrect loader fields (#849)
* loader_fields fix * tested, fixed * added direct file check for invalid file_parts * search fixes * removed printlns * Adds check for loaders * removes println
This commit is contained in:
@@ -836,13 +836,19 @@ impl VersionField {
|
||||
}
|
||||
|
||||
pub fn from_query_json(
|
||||
// A list of all version fields to extract data from
|
||||
query_version_field_combined: Vec<QueryVersionField>,
|
||||
query_loader_fields: &[QueryLoaderField],
|
||||
// A list of all loader fields to reference when extracting data
|
||||
// Note: any loader field in here that is not in query_version_field_combined will be still considered
|
||||
// (For example, game_versions in query_loader_fields but not in query_version_field_combined would produce game_versions: [])
|
||||
query_loader_fields: &[&QueryLoaderField],
|
||||
// enum values to reference when parsing enum values
|
||||
query_loader_field_enum_values: &[QueryLoaderFieldEnumValue],
|
||||
allow_many: bool, // If true, will allow multiple values for a single singleton field, returning them as separate VersionFields
|
||||
// allow_many = true, multiple Bools => two VersionFields of Bool
|
||||
// allow_many = false, multiple Bools => error
|
||||
// multiple Arraybools => 1 VersionField of ArrayBool
|
||||
// If true, will allow multiple values for a single singleton field, returning them as separate VersionFields
|
||||
// allow_many = true, multiple Bools => two VersionFields of Bool
|
||||
// allow_many = false, multiple Bools => error
|
||||
// multiple Arraybools => 1 VersionField of ArrayBool
|
||||
allow_many: bool,
|
||||
) -> Vec<VersionField> {
|
||||
query_loader_fields
|
||||
.iter()
|
||||
|
||||
@@ -607,7 +607,6 @@ impl Project {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let loader_field_ids = DashSet::new();
|
||||
let loader_field_enum_value_ids = DashSet::new();
|
||||
let version_fields: DashMap<ProjectId, Vec<QueryVersionField>> = sqlx::query!(
|
||||
"
|
||||
@@ -630,7 +629,6 @@ impl Project {
|
||||
string_value: m.string_value,
|
||||
};
|
||||
|
||||
loader_field_ids.insert(LoaderFieldId(m.field_id));
|
||||
if let Some(enum_value) = m.enum_value {
|
||||
loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value));
|
||||
}
|
||||
@@ -641,27 +639,6 @@ impl Project {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let loader_fields: Vec<QueryLoaderField> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT id, field, field_type, enum_type, min_val, max_val, optional
|
||||
FROM loader_fields lf
|
||||
WHERE id = ANY($1)
|
||||
",
|
||||
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||
)
|
||||
.fetch(&mut *exec)
|
||||
.map_ok(|m| QueryLoaderField {
|
||||
id: LoaderFieldId(m.id),
|
||||
field: m.field,
|
||||
field_type: m.field_type,
|
||||
enum_type: m.enum_type.map(LoaderFieldEnumId),
|
||||
min_val: m.min_val,
|
||||
max_val: m.max_val,
|
||||
optional: m.optional,
|
||||
})
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
let loader_field_enum_values: Vec<QueryLoaderFieldEnumValue> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT id, enum_id, value, ordering, created, metadata
|
||||
@@ -735,13 +712,22 @@ impl Project {
|
||||
}
|
||||
).await?;
|
||||
|
||||
type StringTriple = (Vec<String>, Vec<String>, Vec<String>);
|
||||
let loaders_ptypes_games: DashMap<ProjectId, StringTriple> = sqlx::query!(
|
||||
#[derive(Default)]
|
||||
struct VersionLoaderData {
|
||||
loaders: Vec<String>,
|
||||
project_types: Vec<String>,
|
||||
games: Vec<String>,
|
||||
loader_loader_field_ids: Vec<LoaderFieldId>,
|
||||
}
|
||||
|
||||
let loader_field_ids = DashSet::new();
|
||||
let loaders_ptypes_games: DashMap<ProjectId, VersionLoaderData> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT mod_id,
|
||||
ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,
|
||||
ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,
|
||||
ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games
|
||||
ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games,
|
||||
ARRAY_AGG(DISTINCT lfl.loader_field_id) filter (where lfl.loader_field_id is not null) loader_fields
|
||||
FROM versions v
|
||||
INNER JOIN loaders_versions lv ON v.id = lv.version_id
|
||||
INNER JOIN loaders l ON lv.loader_id = l.id
|
||||
@@ -749,6 +735,7 @@ impl Project {
|
||||
INNER JOIN project_types pt ON pt.id = lpt.joining_project_type_id
|
||||
INNER JOIN loaders_project_types_games lptg ON lptg.loader_id = l.id AND lptg.project_type_id = pt.id
|
||||
INNER JOIN games g ON lptg.game_id = g.id
|
||||
LEFT JOIN loader_fields_loaders lfl ON lfl.loader_id = l.id
|
||||
WHERE v.id = ANY($1)
|
||||
GROUP BY mod_id
|
||||
",
|
||||
@@ -756,15 +743,47 @@ impl Project {
|
||||
).fetch(&mut *exec)
|
||||
.map_ok(|m| {
|
||||
let project_id = ProjectId(m.mod_id);
|
||||
let loaders = m.loaders.unwrap_or_default();
|
||||
let project_types = m.project_types.unwrap_or_default();
|
||||
let games = m.games.unwrap_or_default();
|
||||
|
||||
(project_id, (loaders, project_types, games))
|
||||
// Add loader fields to the set we need to fetch
|
||||
let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::<Vec<_>>();
|
||||
for loader_field_id in loader_loader_field_ids.iter() {
|
||||
loader_field_ids.insert(*loader_field_id);
|
||||
}
|
||||
|
||||
// Add loader + loader associated data to the map
|
||||
let version_loader_data = VersionLoaderData {
|
||||
loaders: m.loaders.unwrap_or_default(),
|
||||
project_types: m.project_types.unwrap_or_default(),
|
||||
games: m.games.unwrap_or_default(),
|
||||
loader_loader_field_ids,
|
||||
};
|
||||
|
||||
(project_id, version_loader_data)
|
||||
|
||||
}
|
||||
).try_collect().await?;
|
||||
|
||||
let loader_fields: Vec<QueryLoaderField> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT id, field, field_type, enum_type, min_val, max_val, optional
|
||||
FROM loader_fields lf
|
||||
WHERE id = ANY($1)
|
||||
",
|
||||
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||
)
|
||||
.fetch(&mut *exec)
|
||||
.map_ok(|m| QueryLoaderField {
|
||||
id: LoaderFieldId(m.id),
|
||||
field: m.field,
|
||||
field_type: m.field_type,
|
||||
enum_type: m.enum_type.map(LoaderFieldEnumId),
|
||||
min_val: m.min_val,
|
||||
max_val: m.max_val,
|
||||
optional: m.optional,
|
||||
})
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
let db_projects: Vec<QueryProject> = sqlx::query!(
|
||||
"
|
||||
SELECT m.id id, m.name name, m.summary summary, m.downloads downloads, m.follows follows,
|
||||
@@ -791,11 +810,21 @@ impl Project {
|
||||
Ok(e.right().map(|m| {
|
||||
let id = m.id;
|
||||
let project_id = ProjectId(id);
|
||||
let (loaders, project_types, games) = loaders_ptypes_games.remove(&project_id).map(|x| x.1).unwrap_or_default();
|
||||
let VersionLoaderData {
|
||||
loaders,
|
||||
project_types,
|
||||
games,
|
||||
loader_loader_field_ids,
|
||||
} = loaders_ptypes_games.remove(&project_id).map(|x|x.1).unwrap_or_default();
|
||||
let mut versions = versions.remove(&project_id).map(|x| x.1).unwrap_or_default();
|
||||
let mut gallery = mods_gallery.remove(&project_id).map(|x| x.1).unwrap_or_default();
|
||||
let urls = links.remove(&project_id).map(|x| x.1).unwrap_or_default();
|
||||
let version_fields = version_fields.remove(&project_id).map(|x| x.1).unwrap_or_default();
|
||||
|
||||
let loader_fields = loader_fields.iter()
|
||||
.filter(|x| loader_loader_field_ids.contains(&x.id))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
QueryProject {
|
||||
inner: Project {
|
||||
id: ProjectId(id),
|
||||
|
||||
@@ -510,7 +510,6 @@ impl Version {
|
||||
}
|
||||
|
||||
if !version_ids_parsed.is_empty() {
|
||||
let loader_field_ids = DashSet::new();
|
||||
let loader_field_enum_value_ids = DashSet::new();
|
||||
let version_fields: DashMap<VersionId, Vec<QueryVersionField>> = sqlx::query!(
|
||||
"
|
||||
@@ -532,7 +531,6 @@ impl Version {
|
||||
string_value: m.string_value,
|
||||
};
|
||||
|
||||
loader_field_ids.insert(LoaderFieldId(m.field_id));
|
||||
if let Some(enum_value) = m.enum_value {
|
||||
loader_field_enum_value_ids.insert(LoaderFieldEnumValueId(enum_value));
|
||||
}
|
||||
@@ -543,6 +541,57 @@ impl Version {
|
||||
)
|
||||
.await?;
|
||||
|
||||
#[derive(Default)]
|
||||
struct VersionLoaderData {
|
||||
loaders: Vec<String>,
|
||||
project_types: Vec<String>,
|
||||
games: Vec<String>,
|
||||
loader_loader_field_ids: Vec<LoaderFieldId>,
|
||||
}
|
||||
|
||||
let loader_field_ids = DashSet::new();
|
||||
let loaders_ptypes_games: DashMap<VersionId, VersionLoaderData> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT version_id,
|
||||
ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,
|
||||
ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,
|
||||
ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games,
|
||||
ARRAY_AGG(DISTINCT lfl.loader_field_id) filter (where lfl.loader_field_id is not null) loader_fields
|
||||
FROM versions v
|
||||
INNER JOIN loaders_versions lv ON v.id = lv.version_id
|
||||
INNER JOIN loaders l ON lv.loader_id = l.id
|
||||
INNER JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id
|
||||
INNER JOIN project_types pt ON pt.id = lpt.joining_project_type_id
|
||||
INNER JOIN loaders_project_types_games lptg ON lptg.loader_id = l.id AND lptg.project_type_id = pt.id
|
||||
INNER JOIN games g ON lptg.game_id = g.id
|
||||
LEFT JOIN loader_fields_loaders lfl ON lfl.loader_id = l.id
|
||||
WHERE v.id = ANY($1)
|
||||
GROUP BY version_id
|
||||
",
|
||||
&version_ids_parsed
|
||||
).fetch(&mut *exec)
|
||||
.map_ok(|m| {
|
||||
let version_id = VersionId(m.version_id);
|
||||
|
||||
// Add loader fields to the set we need to fetch
|
||||
let loader_loader_field_ids = m.loader_fields.unwrap_or_default().into_iter().map(LoaderFieldId).collect::<Vec<_>>();
|
||||
for loader_field_id in loader_loader_field_ids.iter() {
|
||||
loader_field_ids.insert(*loader_field_id);
|
||||
}
|
||||
|
||||
// Add loader + loader associated data to the map
|
||||
let version_loader_data = VersionLoaderData {
|
||||
loaders: m.loaders.unwrap_or_default(),
|
||||
project_types: m.project_types.unwrap_or_default(),
|
||||
games: m.games.unwrap_or_default(),
|
||||
loader_loader_field_ids,
|
||||
};
|
||||
(version_id,version_loader_data)
|
||||
|
||||
}
|
||||
).try_collect().await?;
|
||||
|
||||
// Fetch all loader fields from any version
|
||||
let loader_fields: Vec<QueryLoaderField> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT id, field, field_type, enum_type, min_val, max_val, optional
|
||||
@@ -588,36 +637,6 @@ impl Version {
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
type StringTriple = (Vec<String>, Vec<String>, Vec<String>);
|
||||
let loaders_ptypes_games: DashMap<VersionId, StringTriple> = sqlx::query!(
|
||||
"
|
||||
SELECT DISTINCT version_id,
|
||||
ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,
|
||||
ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,
|
||||
ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games
|
||||
FROM versions v
|
||||
INNER JOIN loaders_versions lv ON v.id = lv.version_id
|
||||
INNER JOIN loaders l ON lv.loader_id = l.id
|
||||
INNER JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id
|
||||
INNER JOIN project_types pt ON pt.id = lpt.joining_project_type_id
|
||||
INNER JOIN loaders_project_types_games lptg ON lptg.loader_id = l.id AND lptg.project_type_id = pt.id
|
||||
INNER JOIN games g ON lptg.game_id = g.id
|
||||
WHERE v.id = ANY($1)
|
||||
GROUP BY version_id
|
||||
",
|
||||
&version_ids_parsed
|
||||
).fetch(&mut *exec)
|
||||
.map_ok(|m| {
|
||||
let version_id = VersionId(m.version_id);
|
||||
let loaders = m.loaders.unwrap_or_default();
|
||||
let project_types = m.project_types.unwrap_or_default();
|
||||
let games = m.games.unwrap_or_default();
|
||||
|
||||
(version_id, (loaders, project_types, games))
|
||||
|
||||
}
|
||||
).try_collect().await?;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Hash {
|
||||
pub file_id: FileId,
|
||||
@@ -729,12 +748,21 @@ impl Version {
|
||||
Ok(e.right().map(|v|
|
||||
{
|
||||
let version_id = VersionId(v.id);
|
||||
let (loaders, project_types, games) = loaders_ptypes_games.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
let VersionLoaderData {
|
||||
loaders,
|
||||
project_types,
|
||||
games,
|
||||
loader_loader_field_ids,
|
||||
} = loaders_ptypes_games.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
let files = files.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
let hashes = hashes.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
let version_fields = version_fields.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
let dependencies = dependencies.remove(&version_id).map(|x|x.1).unwrap_or_default();
|
||||
|
||||
let loader_fields = loader_fields.iter()
|
||||
.filter(|x| loader_loader_field_ids.contains(&x.id))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
QueryVersion {
|
||||
inner: Version {
|
||||
id: VersionId(v.id),
|
||||
|
||||
Reference in New Issue
Block a user