diff --git a/sr_download/src/config.rs b/sr_download/src/config.rs index dcbce42..2837f0a 100644 --- a/sr_download/src/config.rs +++ b/sr_download/src/config.rs @@ -2,6 +2,8 @@ use std::path::Path; use serde::{Deserialize, Serialize}; +use crate::SaveId; + #[derive(Serialize, Deserialize)] pub struct ConfigFile { pub db_url: String, @@ -10,6 +12,7 @@ pub struct ConfigFile { pub sqlx_logging: bool, pub worker_count: u32, pub worker_size: u32, + pub start_id: SaveId, } impl Default for ConfigFile { @@ -21,6 +24,7 @@ impl Default for ConfigFile { sqlx_logging: true, worker_count: 10, worker_size: 10, + start_id: 1, } } } diff --git a/sr_download/src/main.rs b/sr_download/src/main.rs index 68d5020..199dd39 100644 --- a/sr_download/src/main.rs +++ b/sr_download/src/main.rs @@ -13,6 +13,8 @@ pub const TEXT_DATA_MAX_LEN: usize = 1024; use model::sea_orm_active_enums::SaveType; +use crate::db_part::CoverStrategy; + async fn big_worker(db: sea_orm::DatabaseConnection, work_range: Range) { let client = net::Downloader::default(); for work_id in work_range { @@ -21,10 +23,22 @@ async fn big_worker(db: sea_orm::DatabaseConnection, work_range: Range) event!( Level::INFO, "{}", - format!("Download {} with data len: {}", work_id, file.len()).green() + format!( + "Download {} with {} data len: {}", + work_id, + file.type_name(), + file.len() + ) + .green() ); let save_type = (&file).into(); - db_part::save_data_to_db(work_id, save_type, file.take_data(), None, &db) + db_part::save_data_to_db( + work_id, + save_type, + file.take_data(), + Some(CoverStrategy::CoverIfDifferent), + &db, + ) } None => { event!( @@ -57,14 +71,14 @@ async fn main() -> anyhow::Result<()> { }; let db_connect = db_part::connect(&conf).await?; - let start_id = db_part::find_max_id(&db_connect).await; + let db_max_id = db_part::find_max_id(&db_connect).await; - event!(Level::INFO, "Starting download from save_id: {}", start_id); + event!(Level::INFO, "db max downloaded save_id: {}", db_max_id); // 1321469 end let end_id: SaveId = 1321469; - let mut current_id = start_id; + let mut current_id = conf.start_id; let batch_size = conf.worker_size; // 10 works @@ -90,7 +104,7 @@ async fn main() -> anyhow::Result<()> { } if !works.is_empty() { - let (result, index, remain) = select_all(works).await; + let (_result, _index, remain) = select_all(works).await; works = remain; } } diff --git a/sr_download/src/net.rs b/sr_download/src/net.rs index d538d9c..8e7b41e 100644 --- a/sr_download/src/net.rs +++ b/sr_download/src/net.rs @@ -47,6 +47,12 @@ impl DownloadFile { DownloadFile::Save(s) => s.len(), } } + pub fn type_name(&self) -> &'static str { + match self { + DownloadFile::Ship(_) => "Ship", + DownloadFile::Save(_) => "Save", + } + } } impl From<&DownloadFile> for SaveType {