From 188d96311292c117b55ac9c66fe4b98e3e58f488 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 7 Oct 2021 00:16:03 +0200 Subject: [PATCH] Remove doublicate logging --- src/steam/utils.rs | 7 +------ src/steamgriddb/downloader.rs | 29 ++++++++++++++++++----------- src/sync/sync.rs | 9 +++++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/steam/utils.rs b/src/steam/utils.rs index 0e5c6d4..3eaca71 100644 --- a/src/steam/utils.rs +++ b/src/steam/utils.rs @@ -18,12 +18,7 @@ pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo { .unwrap() .iter() .map(|s| s.to_owned()) - .collect(); - println!( - "Found {} shortcuts for user: {}", - shortcuts.len(), - user.steam_user_data_folder - ); + .collect(); Path::new(&shortcut_path).to_path_buf() } None => { diff --git a/src/steamgriddb/downloader.rs b/src/steamgriddb/downloader.rs index 86aa210..9d466dd 100644 --- a/src/steamgriddb/downloader.rs +++ b/src/steamgriddb/downloader.rs @@ -18,27 +18,37 @@ use super::CachedSearch; const CONCURRENT_REQUESTS: usize = 10; pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec) { + let start_time = std::time::Instant::now(); + let to_downloads = stream::iter(users) .map(|user| { let shortcut_info = get_shortcuts_for_user(user); async move { - find_art(settings, user, &shortcut_info.shortcuts) + start_search_for_to_download(settings, user, &shortcut_info.shortcuts) .await .unwrap_or(vec![]) } }) - .buffer_unordered(CONCURRENT_REQUESTS); - let to_download = to_downloads.flat_map(futures::stream::iter); - to_download - .for_each(|to_download| async move { + .buffer_unordered(CONCURRENT_REQUESTS) + .collect::>>() + .await; + let to_downloads = to_downloads.iter().flatten().collect::>(); + + stream::iter(to_downloads) + .map(|to_download| async move { if let Err(e) = download_to_download(&to_download).await { println!("Error downloading {:?}: {}", &to_download.path, e); } }) + .buffer_unordered(CONCURRENT_REQUESTS) + .collect::>() .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, user: &crate::steam::SteamUsersInfo, shortcut_info: &Vec, @@ -46,12 +56,11 @@ async fn find_art( let auth_key = &settings.steamgrid_db.auth_key; if let Some(auth_key) = auth_key { - let start_time = std::time::Instant::now(); println!("Checking for game images"); let client = steamgriddb_api::Client::new(auth_key); let mut search = CachedSearch::new(&client); let known_images = get_users_images(user).unwrap(); - let res = download_images( + let res = search_fo_to_download( known_images, user.steam_user_data_folder.as_str(), shortcut_info, @@ -60,8 +69,6 @@ async fn find_art( ) .await?; search.save(); - let duration = start_time.elapsed(); - println!("Finished getting images in: {:?}", duration); Ok(res) } else { 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, user_data_folder: &str, shortcuts: &Vec, diff --git a/src/sync/sync.rs b/src/sync/sync.rs index e9a7696..8621831 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -6,7 +6,7 @@ use crate::{ platform::Platform, settings::Settings, steam::{get_shortcuts_for_user, get_shortcuts_paths}, - steamgriddb::{download_images_for_users}, + steamgriddb::download_images_for_users, }; use std::error::Error; @@ -20,6 +20,12 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box> { let start_time = std::time::Instant::now(); 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); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); @@ -93,7 +99,6 @@ where T: Into, { if platform.enabled() { - #[cfg(target_os = "linux")] if platform.create_symlinks() { let name = platform.name();