Dump plugins by hash instead of id

The same exact plugins are often included in many different files/mods. Grouping by hash in the sql query will show all files and mods a plugin appears in. Previously, the last file that was processed would overwrite the plugin file and only that single file/mod would appear in the file.

Also adds an index on plugins.hash since I'm now querying directly on it.
This commit is contained in:
Tyler Hallada
2022-03-12 13:05:21 -05:00
parent c9dcd3b7c5
commit 5d55e78283
3 changed files with 24 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ fn format_radix(mut x: u64, radix: u32) -> String {
let mut result = vec![];
loop {
let m = x % radix as u64;
x = x / radix as u64;
x /= radix as u64;
// will panic if you use a bad radix (< 2 or > 36).
result.push(std::char::from_digit(m as u32, radix).unwrap());
@@ -23,10 +23,10 @@ fn format_radix(mut x: u64, radix: u32) -> String {
pub async fn dump_plugin_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str) -> Result<()> {
let page_size = 20;
let mut last_id = None;
let mut last_hash = None;
loop {
let plugins =
plugin::batched_get_with_data(&pool, page_size, last_id, "Skyrim.esm", 1).await?;
plugin::batched_get_by_hash_with_mods(pool, page_size, last_hash, "Skyrim.esm", 1).await?;
if plugins.is_empty() {
break;
}
@@ -36,8 +36,8 @@ pub async fn dump_plugin_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str) -> R
let path = path.join(format!("{}.json", format_radix(plugin.hash as u64, 36)));
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&plugin)?)?;
last_id = Some(plugin.id);
last_hash = Some(plugin.hash);
}
}
return Ok(());
Ok(())
}