Remove doublicate logging

This commit is contained in:
Philip
2021-10-07 00:16:03 +02:00
parent 7b6f318e90
commit 188d963112
3 changed files with 26 additions and 19 deletions
+1 -6
View File
@@ -18,12 +18,7 @@ pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
.unwrap() .unwrap()
.iter() .iter()
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect(); .collect();
println!(
"Found {} shortcuts for user: {}",
shortcuts.len(),
user.steam_user_data_folder
);
Path::new(&shortcut_path).to_path_buf() Path::new(&shortcut_path).to_path_buf()
} }
None => { None => {
+18 -11
View File
@@ -18,27 +18,37 @@ use super::CachedSearch;
const CONCURRENT_REQUESTS: usize = 10; const CONCURRENT_REQUESTS: usize = 10;
pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<SteamUsersInfo>) { pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<SteamUsersInfo>) {
let start_time = std::time::Instant::now();
let to_downloads = stream::iter(users) let to_downloads = stream::iter(users)
.map(|user| { .map(|user| {
let shortcut_info = get_shortcuts_for_user(user); let shortcut_info = get_shortcuts_for_user(user);
async move { async move {
find_art(settings, user, &shortcut_info.shortcuts) start_search_for_to_download(settings, user, &shortcut_info.shortcuts)
.await .await
.unwrap_or(vec![]) .unwrap_or(vec![])
} }
}) })
.buffer_unordered(CONCURRENT_REQUESTS); .buffer_unordered(CONCURRENT_REQUESTS)
let to_download = to_downloads.flat_map(futures::stream::iter); .collect::<Vec<Vec<ToDownload>>>()
to_download .await;
.for_each(|to_download| async move { let to_downloads = to_downloads.iter().flatten().collect::<Vec<&ToDownload>>();
stream::iter(to_downloads)
.map(|to_download| async move {
if let Err(e) = download_to_download(&to_download).await { if let Err(e) = download_to_download(&to_download).await {
println!("Error downloading {:?}: {}", &to_download.path, e); println!("Error downloading {:?}: {}", &to_download.path, e);
} }
}) })
.buffer_unordered(CONCURRENT_REQUESTS)
.collect::<Vec<()>>()
.await; .await;
let duration = start_time.elapsed();
println!("Finished getting images in: {:?}", duration);
} }
async fn find_art( async fn start_search_for_to_download(
settings: &Settings, settings: &Settings,
user: &crate::steam::SteamUsersInfo, user: &crate::steam::SteamUsersInfo,
shortcut_info: &Vec<ShortcutOwned>, shortcut_info: &Vec<ShortcutOwned>,
@@ -46,12 +56,11 @@ async fn find_art(
let auth_key = &settings.steamgrid_db.auth_key; let auth_key = &settings.steamgrid_db.auth_key;
if let Some(auth_key) = auth_key { if let Some(auth_key) = auth_key {
let start_time = std::time::Instant::now();
println!("Checking for game images"); println!("Checking for game images");
let client = steamgriddb_api::Client::new(auth_key); let client = steamgriddb_api::Client::new(auth_key);
let mut search = CachedSearch::new(&client); let mut search = CachedSearch::new(&client);
let known_images = get_users_images(user).unwrap(); let known_images = get_users_images(user).unwrap();
let res = download_images( let res = search_fo_to_download(
known_images, known_images,
user.steam_user_data_folder.as_str(), user.steam_user_data_folder.as_str(),
shortcut_info, shortcut_info,
@@ -60,8 +69,6 @@ async fn find_art(
) )
.await?; .await?;
search.save(); search.save();
let duration = start_time.elapsed();
println!("Finished getting images in: {:?}", duration);
Ok(res) Ok(res)
} else { } else {
println!("Steamgrid DB Auth Key not found, please add one as described here: https://github.com/PhilipK/steam_shortcuts_sync#configuration"); println!("Steamgrid DB Auth Key not found, please add one as described here: https://github.com/PhilipK/steam_shortcuts_sync#configuration");
@@ -69,7 +76,7 @@ async fn find_art(
} }
} }
async fn download_images<'b>( async fn search_fo_to_download<'b>(
known_images: Vec<String>, known_images: Vec<String>,
user_data_folder: &str, user_data_folder: &str,
shortcuts: &Vec<ShortcutOwned>, shortcuts: &Vec<ShortcutOwned>,
+7 -2
View File
@@ -6,7 +6,7 @@ use crate::{
platform::Platform, platform::Platform,
settings::Settings, settings::Settings,
steam::{get_shortcuts_for_user, get_shortcuts_paths}, steam::{get_shortcuts_for_user, get_shortcuts_paths},
steamgriddb::{download_images_for_users}, steamgriddb::download_images_for_users,
}; };
use std::error::Error; use std::error::Error;
@@ -20,6 +20,12 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
let mut shortcut_info = get_shortcuts_for_user(user); let mut shortcut_info = get_shortcuts_for_user(user);
println!(
"Found {} shortcuts for user: {}",
shortcut_info.shortcuts.len(),
user.steam_user_data_folder
);
update_platforms(settings, &mut shortcut_info.shortcuts); update_platforms(settings, &mut shortcut_info.shortcuts);
save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path));
@@ -93,7 +99,6 @@ where
T: Into<ShortcutOwned>, T: Into<ShortcutOwned>,
{ {
if platform.enabled() { if platform.enabled() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
if platform.create_symlinks() { if platform.create_symlinks() {
let name = platform.name(); let name = platform.name();