You've already forked AstralRinth
forked from didirus/AstralRinth
Query Optimization
This commit is contained in:
@@ -401,108 +401,87 @@ impl Mod {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let result = Self::get(id, executor).await?;
|
||||
if let Some(inner) = result {
|
||||
use futures::TryStreamExt;
|
||||
let categories: Vec<String> = sqlx::query!(
|
||||
"
|
||||
SELECT category FROM mods_categories
|
||||
INNER JOIN categories ON joining_category_id = id
|
||||
WHERE joining_mod_id = $1
|
||||
",
|
||||
id as ModId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| c.category)) })
|
||||
.try_collect::<Vec<String>>()
|
||||
.await?;
|
||||
|
||||
let versions: Vec<VersionId> = sqlx::query!(
|
||||
"
|
||||
SELECT id FROM versions
|
||||
WHERE mod_id = $1
|
||||
",
|
||||
id as ModId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| VersionId(c.id))) })
|
||||
.try_collect::<Vec<VersionId>>()
|
||||
.await?;
|
||||
|
||||
let donations: Vec<DonationUrl> = sqlx::query!(
|
||||
"
|
||||
SELECT d.joining_platform_id, d.url, dp.short, dp.name FROM mods_donations d
|
||||
INNER JOIN donation_platforms dp ON d.joining_platform_id=dp.id
|
||||
WHERE joining_mod_id = $1
|
||||
",
|
||||
id as ModId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|c| DonationUrl {
|
||||
mod_id: id,
|
||||
platform_id: DonationPlatformId(c.joining_platform_id),
|
||||
platform_short: c.short,
|
||||
platform_name: c.name,
|
||||
url: c.url,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<DonationUrl>>()
|
||||
.await?;
|
||||
|
||||
let status = sqlx::query!(
|
||||
"
|
||||
SELECT status FROM statuses
|
||||
WHERE id = $1
|
||||
",
|
||||
inner.status.0,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await?
|
||||
.status;
|
||||
|
||||
let client_side = sqlx::query!(
|
||||
"
|
||||
SELECT name FROM side_types
|
||||
WHERE id = $1
|
||||
",
|
||||
inner.client_side.0,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await?
|
||||
.name;
|
||||
|
||||
let server_side = sqlx::query!(
|
||||
"
|
||||
SELECT name FROM side_types
|
||||
WHERE id = $1
|
||||
",
|
||||
inner.server_side.0,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await?
|
||||
.name;
|
||||
|
||||
let license = sqlx::query!(
|
||||
"
|
||||
SELECT short, name FROM licenses
|
||||
WHERE id = $1
|
||||
",
|
||||
inner.license.0,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT m.id id, m.title title, m.description description, m.downloads downloads,
|
||||
m.icon_url icon_url, m.body body, m.body_url body_url, m.published published,
|
||||
m.updated updated, m.status 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,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
||||
ARRAY_AGG( DISTINCT c.category) categories, ARRAY_AGG(DISTINCT v.id) versions, ARRAY_AGG(DISTINCT md.joining_platform_id || ', ' || md.url || ', ' || dp.short || ', ' || dp.name) donations
|
||||
FROM mods m
|
||||
INNER JOIN mods_categories mc ON joining_mod_id = m.id
|
||||
INNER JOIN categories c ON mc.joining_category_id = c.id
|
||||
INNER JOIN versions v ON v.mod_id = m.id
|
||||
INNER JOIN mods_donations md ON md.joining_mod_id = m.id
|
||||
INNER JOIN donation_platforms dp ON md.joining_platform_id = dp.id
|
||||
INNER JOIN statuses s ON s.id = m.status
|
||||
INNER JOIN side_types cs ON m.client_side = cs.id
|
||||
INNER JOIN side_types ss ON m.server_side = ss.id
|
||||
INNER JOIN licenses l ON m.license = l.id
|
||||
WHERE m.id IN (SELECT * FROM UNNEST($1::bigint[]))
|
||||
GROUP BY m.id, s.id, cs.id, ss.id, l.id;
|
||||
",
|
||||
id as ModId,
|
||||
)
|
||||
.fetch_optional(executor)
|
||||
.await?;
|
||||
|
||||
if let Some(m) = result {
|
||||
Ok(Some(QueryMod {
|
||||
inner,
|
||||
categories,
|
||||
versions,
|
||||
donation_urls: donations,
|
||||
status: crate::models::mods::ModStatus::from_str(&status),
|
||||
license_id: license.short,
|
||||
license_name: license.name,
|
||||
client_side: crate::models::mods::SideType::from_str(&client_side),
|
||||
server_side: crate::models::mods::SideType::from_str(&server_side),
|
||||
inner: Mod {
|
||||
id: ModId(m.id.clone()),
|
||||
team_id: TeamId(m.team_id.clone()),
|
||||
title: m.title.clone(),
|
||||
description: m.description.clone(),
|
||||
downloads: m.downloads.clone(),
|
||||
body_url: m.body_url.clone(),
|
||||
icon_url: m.icon_url.clone(),
|
||||
published: m.published.clone(),
|
||||
updated: m.updated.clone(),
|
||||
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.clone()),
|
||||
status: StatusId(m.status.clone()),
|
||||
server_side: SideTypeId(m.server_side.clone()),
|
||||
license: LicenseId(m.license.clone()),
|
||||
slug: m.slug.clone(),
|
||||
body: m.body.clone(),
|
||||
},
|
||||
categories: m.categories.clone().unwrap_or(vec![]),
|
||||
versions: m
|
||||
.versions
|
||||
.clone()
|
||||
.unwrap_or(vec![])
|
||||
.into_iter()
|
||||
.map(|v| VersionId(v))
|
||||
.collect(),
|
||||
donation_urls: m
|
||||
.donations
|
||||
.clone()
|
||||
.unwrap_or(vec![])
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
// TODO: Change this once SQLX allows postgres tuples
|
||||
let strings: Vec<&str> = d.split(", ").collect();
|
||||
DonationUrl {
|
||||
mod_id: ModId(m.id.clone()),
|
||||
platform_id: DonationPlatformId(strings[0].parse().unwrap_or(0)),
|
||||
platform_short: strings[2].to_string(),
|
||||
platform_name: strings[3].to_string(),
|
||||
url: strings[1].to_string(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
||||
license_id: m.short,
|
||||
license_name: m.license_name,
|
||||
client_side: crate::models::mods::SideType::from_str(&m.client_side_type),
|
||||
server_side: crate::models::mods::SideType::from_str(&m.server_side_type),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -512,19 +491,84 @@ impl Mod {
|
||||
pub async fn get_many_full<'a, E>(
|
||||
mod_ids: Vec<ModId>,
|
||||
exec: E,
|
||||
) -> Result<Vec<Option<QueryMod>>, sqlx::Error>
|
||||
) -> Result<Vec<QueryMod>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let mut mods = Vec::new();
|
||||
use futures::TryStreamExt;
|
||||
|
||||
for mod_id in mod_ids {
|
||||
mods.push(Self::get_full(mod_id, exec).await?)
|
||||
}
|
||||
|
||||
Ok(mods)
|
||||
/*// TODO: this could be optimized
|
||||
futures::future::try_join_all(mod_ids.into_iter().map(|id| Self::get_full(id, exec))).await*/
|
||||
let mod_ids_parsed: Vec<i64> = mod_ids.into_iter().map(|x| x.0).collect();
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT m.id id, m.title title, m.description description, m.downloads downloads,
|
||||
m.icon_url icon_url, m.body body, m.body_url body_url, m.published published,
|
||||
m.updated updated, m.status 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,
|
||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
||||
ARRAY_AGG( DISTINCT c.category) categories, ARRAY_AGG(DISTINCT v.id) versions, ARRAY_AGG(DISTINCT md.joining_platform_id || ', ' || md.url || ', ' || dp.short || ', ' || dp.name) donations
|
||||
FROM mods m
|
||||
INNER JOIN mods_categories mc ON joining_mod_id = m.id
|
||||
INNER JOIN categories c ON mc.joining_category_id = c.id
|
||||
INNER JOIN versions v ON v.mod_id = m.id
|
||||
INNER JOIN mods_donations md ON md.joining_mod_id = m.id
|
||||
INNER JOIN donation_platforms dp ON md.joining_platform_id = dp.id
|
||||
INNER JOIN statuses s ON s.id = m.status
|
||||
INNER JOIN side_types cs ON m.client_side = cs.id
|
||||
INNER JOIN side_types ss ON m.server_side = ss.id
|
||||
INNER JOIN licenses l ON m.license = l.id
|
||||
WHERE m.id IN (SELECT * FROM UNNEST($1::bigint[]))
|
||||
GROUP BY m.id, s.id, cs.id, ss.id, l.id;
|
||||
",
|
||||
&mod_ids_parsed
|
||||
)
|
||||
.fetch_many(exec)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|m| QueryMod {
|
||||
inner: Mod {
|
||||
id: ModId(m.id.clone()),
|
||||
team_id: TeamId(m.team_id.clone()),
|
||||
title: m.title.clone(),
|
||||
description: m.description.clone(),
|
||||
downloads: m.downloads.clone(),
|
||||
body_url: m.body_url.clone(),
|
||||
icon_url: m.icon_url.clone(),
|
||||
published: m.published.clone(),
|
||||
updated: m.updated.clone(),
|
||||
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.clone()),
|
||||
status: StatusId(m.status.clone()),
|
||||
server_side: SideTypeId(m.server_side.clone()),
|
||||
license: LicenseId(m.license.clone()),
|
||||
slug: m.slug.clone(),
|
||||
body: m.body.clone(),
|
||||
},
|
||||
categories: m.categories.clone().unwrap_or(vec![]),
|
||||
versions: m.versions.clone().unwrap_or(vec![]).into_iter().map(|v| VersionId(v)).collect(),
|
||||
donation_urls: m.donations.clone().unwrap_or(vec![]).into_iter().map(|d| {
|
||||
// TODO: Change this once SQLX allows postgres tuples
|
||||
let strings : Vec<&str> = d.split(", ").collect();
|
||||
DonationUrl {
|
||||
mod_id: ModId(m.id.clone()),
|
||||
platform_id: DonationPlatformId(strings[0].parse().unwrap_or(0)),
|
||||
platform_short: strings[2].to_string(),
|
||||
platform_name: strings[3].to_string(),
|
||||
url: strings[1].to_string()
|
||||
}
|
||||
}).collect(),
|
||||
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
||||
license_id: m.short,
|
||||
license_name: m.license_name,
|
||||
client_side: crate::models::mods::SideType::from_str(&m.client_side_type),
|
||||
server_side: crate::models::mods::SideType::from_str(&m.server_side_type),
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<QueryMod>>()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::ids::*;
|
||||
use super::DatabaseError;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct VersionBuilder {
|
||||
pub version_id: VersionId,
|
||||
@@ -461,100 +462,78 @@ impl Version {
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT v.mod_id, v.author_id, v.name, v.version_number,
|
||||
v.changelog, v.changelog_url, v.date_published, v.downloads,
|
||||
release_channels.channel, v.featured
|
||||
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
||||
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
||||
rc.channel release_channel, v.featured featured,
|
||||
ARRAY_AGG(gv.version ORDER BY gv.created) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,
|
||||
ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,
|
||||
ARRAY_AGG(DISTINCT h.hash || ', ' || h.algorithm || ', ' || h.file_id) hashes
|
||||
FROM versions v
|
||||
INNER JOIN release_channels ON v.release_channel = release_channels.id
|
||||
INNER JOIN release_channels rc on v.release_channel = rc.id
|
||||
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
|
||||
INNER JOIN loaders_versions lv on v.id = lv.version_id
|
||||
INNER JOIN loaders l on lv.loader_id = l.id
|
||||
INNER JOIN files f on v.id = f.version_id
|
||||
INNER JOIN hashes h on f.id = h.file_id
|
||||
WHERE v.id = $1
|
||||
GROUP BY v.id, rc.id;
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_optional(executor)
|
||||
.await?;
|
||||
|
||||
if let Some(row) = result {
|
||||
use futures::TryStreamExt;
|
||||
|
||||
let game_versions: Vec<String> = sqlx::query!(
|
||||
"
|
||||
SELECT gv.version FROM game_versions_versions gvv
|
||||
INNER JOIN game_versions gv ON gvv.game_version_id=gv.id
|
||||
WHERE gvv.joining_version_id = $1
|
||||
ORDER BY gv.created
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| c.version)) })
|
||||
.try_collect::<Vec<String>>()
|
||||
.fetch_optional(executor)
|
||||
.await?;
|
||||
|
||||
let loaders: Vec<String> = sqlx::query!(
|
||||
"
|
||||
SELECT loaders.loader FROM loaders
|
||||
INNER JOIN loaders_versions ON loaders.id = loaders_versions.loader_id
|
||||
WHERE loaders_versions.version_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| c.loader)) })
|
||||
.try_collect::<Vec<String>>()
|
||||
.await?;
|
||||
if let Some(v) = result {
|
||||
let mut hashes: Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
||||
|
||||
let mut files = sqlx::query!(
|
||||
"
|
||||
SELECT files.id, files.url, files.filename, files.is_primary FROM files
|
||||
WHERE files.version_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|c| QueryFile {
|
||||
id: FileId(c.id),
|
||||
url: c.url,
|
||||
filename: c.filename,
|
||||
hashes: std::collections::HashMap::new(),
|
||||
primary: c.is_primary,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<QueryFile>>()
|
||||
.await?;
|
||||
|
||||
for file in files.iter_mut() {
|
||||
let files = sqlx::query!(
|
||||
"
|
||||
SELECT hashes.algorithm, hashes.hash FROM hashes
|
||||
WHERE hashes.file_id = $1
|
||||
",
|
||||
file.id as FileId
|
||||
)
|
||||
.fetch_many(executor)
|
||||
.try_filter_map(|e| async { Ok(e.right().map(|c| (c.algorithm, c.hash))) })
|
||||
.try_collect::<Vec<(String, Vec<u8>)>>()
|
||||
.await?;
|
||||
|
||||
file.hashes.extend(files);
|
||||
}
|
||||
v.hashes.unwrap_or(vec![]).into_iter().for_each(|f| {
|
||||
let hash: Vec<&str> = f.split(", ").collect();
|
||||
hashes.push((
|
||||
FileId(hash[2].parse().unwrap_or(0)),
|
||||
hash[1].to_string(),
|
||||
hash[0].to_string().into_bytes(),
|
||||
));
|
||||
});
|
||||
|
||||
Ok(Some(QueryVersion {
|
||||
id,
|
||||
mod_id: ModId(row.mod_id),
|
||||
author_id: UserId(row.author_id),
|
||||
name: row.name,
|
||||
version_number: row.version_number,
|
||||
changelog: row.changelog,
|
||||
changelog_url: row.changelog_url,
|
||||
date_published: row.date_published,
|
||||
downloads: row.downloads,
|
||||
id: VersionId(v.id),
|
||||
mod_id: ModId(v.mod_id),
|
||||
author_id: UserId(v.author_id),
|
||||
name: v.version_name,
|
||||
version_number: v.version_number,
|
||||
changelog: v.changelog,
|
||||
changelog_url: v.changelog_url,
|
||||
date_published: v.date_published,
|
||||
downloads: v.downloads,
|
||||
release_channel: v.release_channel,
|
||||
files: v
|
||||
.files
|
||||
.unwrap_or(vec![])
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
let file: Vec<&str> = f.split(", ").collect();
|
||||
let file_id = FileId(file[0].parse().unwrap_or(0));
|
||||
let mut file_hashes = HashMap::new();
|
||||
|
||||
release_channel: row.channel,
|
||||
files,
|
||||
loaders,
|
||||
game_versions,
|
||||
featured: row.featured,
|
||||
for hash in &hashes {
|
||||
if hash.0 .0 == file_id.0 {
|
||||
file_hashes.insert(hash.1.clone(), hash.2.clone());
|
||||
}
|
||||
}
|
||||
|
||||
QueryFile {
|
||||
id: file_id,
|
||||
url: file[3].to_string(),
|
||||
filename: file[1].to_string(),
|
||||
hashes: file_hashes,
|
||||
primary: file[3].parse().unwrap_or(false),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
game_versions: v.game_versions.unwrap_or(vec![]),
|
||||
loaders: v.loaders.unwrap_or(vec![]),
|
||||
featured: v.featured,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -564,19 +543,82 @@ impl Version {
|
||||
pub async fn get_many_full<'a, E>(
|
||||
version_ids: Vec<VersionId>,
|
||||
exec: E,
|
||||
) -> Result<Vec<Option<QueryVersion>>, sqlx::Error>
|
||||
) -> Result<Vec<QueryVersion>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let mut versions = Vec::new();
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
for version_id in version_ids {
|
||||
versions.push(Self::get_full(version_id, exec).await?)
|
||||
}
|
||||
let version_ids_parsed: Vec<i64> = version_ids.into_iter().map(|x| x.0).collect();
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
||||
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
||||
rc.channel release_channel, v.featured featured,
|
||||
ARRAY_AGG(gv.version ORDER BY gv.created) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,
|
||||
ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,
|
||||
ARRAY_AGG(DISTINCT h.hash || ', ' || h.algorithm || ', ' || h.file_id) hashes
|
||||
FROM versions v
|
||||
INNER JOIN release_channels rc on v.release_channel = rc.id
|
||||
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
|
||||
INNER JOIN loaders_versions lv on v.id = lv.version_id
|
||||
INNER JOIN loaders l on lv.loader_id = l.id
|
||||
INNER JOIN files f on v.id = f.version_id
|
||||
INNER JOIN hashes h on f.id = h.file_id
|
||||
WHERE v.id IN (SELECT * FROM UNNEST($1::bigint[]))
|
||||
GROUP BY v.id, rc.id;
|
||||
",
|
||||
&version_ids_parsed
|
||||
)
|
||||
.fetch_many(exec)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|v| {
|
||||
let mut hashes : Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
||||
|
||||
Ok(versions)
|
||||
/* futures::future::try_join_all(version_ids.into_iter().map(|id| Self::get_full(id, exec)))
|
||||
.await*/
|
||||
v.hashes.unwrap_or(vec![]).into_iter().for_each(|f| {
|
||||
let hash : Vec<&str> = f.split(", ").collect();
|
||||
hashes.push((FileId(hash[2].parse().unwrap_or(0)), hash[1].to_string(), hash[0].to_string().into_bytes()));
|
||||
});
|
||||
|
||||
QueryVersion {
|
||||
id: VersionId(v.id),
|
||||
mod_id: ModId(v.mod_id),
|
||||
author_id: UserId(v.author_id),
|
||||
name: v.version_name,
|
||||
version_number: v.version_number,
|
||||
changelog: v.changelog,
|
||||
changelog_url: v.changelog_url,
|
||||
date_published: v.date_published,
|
||||
downloads: v.downloads,
|
||||
release_channel: v.release_channel,
|
||||
files: v.files.unwrap_or(vec![]).into_iter().map(|f| {
|
||||
let file : Vec<&str> = f.split(", ").collect();
|
||||
let file_id = FileId(file[0].parse().unwrap_or(0));
|
||||
let mut file_hashes = HashMap::new();
|
||||
|
||||
for hash in &hashes {
|
||||
if hash.0.0 == file_id.0 {
|
||||
file_hashes.insert(hash.1.clone(), hash.2.clone());
|
||||
}
|
||||
}
|
||||
|
||||
QueryFile {
|
||||
id: file_id,
|
||||
url: file[3].to_string(),
|
||||
filename: file[1].to_string(),
|
||||
hashes: file_hashes,
|
||||
primary: file[3].parse().unwrap_or(false)
|
||||
}
|
||||
}).collect(),
|
||||
game_versions: v.game_versions.unwrap_or(vec![]),
|
||||
loaders: v.loaders.unwrap_or(vec![]),
|
||||
featured: v.featured,
|
||||
}
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<QueryVersion>>()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,6 +663,6 @@ pub struct QueryFile {
|
||||
pub id: FileId,
|
||||
pub url: String,
|
||||
pub filename: String,
|
||||
pub hashes: std::collections::HashMap<String, Vec<u8>>,
|
||||
pub hashes: HashMap<String, Vec<u8>>,
|
||||
pub primary: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user