Make separate mod search indices per game instead

Saves significant amount of space in the json if I don't need to list a game name for every mod.
This commit is contained in:
2022-09-03 00:49:57 -04:00
parent 84a02971a0
commit 14be03cd3d
5 changed files with 27 additions and 11 deletions

View File

@@ -11,18 +11,17 @@ use crate::models::game_mod;
#[derive(Serialize)]
struct ModForSearchIdTranslated {
name: String,
game: String,
id: i32,
}
pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, path: &str) -> Result<()> {
pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, game: &str, path: &str) -> Result<()> {
let mut page = 1;
let mut search_index = vec![];
let page_size = 20;
let mut last_id = None;
let game_id_to_names: HashMap<_, _> = game::get_all(&pool).await?.into_iter().map(|game| (game.id, game.name)).collect();
let game_id = game::get_id_by_name(&pool, game).await?;
loop {
let mods = game_mod::batched_get_for_search(&pool, page_size, last_id).await?;
let mods = game_mod::batched_get_for_search(&pool, game_id, page_size, last_id).await?;
if mods.is_empty() {
break;
}
@@ -30,7 +29,6 @@ pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, path: &str
info!(page = page, nexus_mod_id = mod_for_search.nexus_mod_id, "read mod name for search index");
search_index.push(ModForSearchIdTranslated {
name: mod_for_search.name,
game: game_id_to_names.get(&mod_for_search.game_id).expect("known game id").to_string(),
id: mod_for_search.nexus_mod_id,
});
last_id = Some(mod_for_search.id);