Add game names to mod search index
This commit is contained in:
parent
782f7a473f
commit
84a02971a0
@ -1,14 +1,17 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
use crate::models::game;
|
||||||
use crate::models::game_mod;
|
use crate::models::game_mod;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct ModForSearchIdTranslated {
|
struct ModForSearchIdTranslated {
|
||||||
name: String,
|
name: String,
|
||||||
|
game: String,
|
||||||
id: i32,
|
id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,6 +20,7 @@ pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, path: &str
|
|||||||
let mut search_index = vec![];
|
let mut search_index = vec![];
|
||||||
let page_size = 20;
|
let page_size = 20;
|
||||||
let mut last_id = None;
|
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();
|
||||||
loop {
|
loop {
|
||||||
let mods = game_mod::batched_get_for_search(&pool, page_size, last_id).await?;
|
let mods = game_mod::batched_get_for_search(&pool, page_size, last_id).await?;
|
||||||
if mods.is_empty() {
|
if mods.is_empty() {
|
||||||
@ -26,6 +30,7 @@ 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");
|
info!(page = page, nexus_mod_id = mod_for_search.nexus_mod_id, "read mod name for search index");
|
||||||
search_index.push(ModForSearchIdTranslated {
|
search_index.push(ModForSearchIdTranslated {
|
||||||
name: mod_for_search.name,
|
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,
|
id: mod_for_search.nexus_mod_id,
|
||||||
});
|
});
|
||||||
last_id = Some(mod_for_search.id);
|
last_id = Some(mod_for_search.id);
|
||||||
|
Loading…
Reference in New Issue
Block a user