Skip to content

Commit 06de2bd

Browse files
committed
Do not search for more than 99 images at a time
1 parent e9d1049 commit 06de2bd

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/steamgriddb/downloader.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub async fn download_images_for_users<'b>(
4343
let shortcut_info = get_shortcuts_for_user(user);
4444
async move {
4545
let known_images = get_users_images(user).unwrap_or_default();
46-
let res = search_fo_to_download(
46+
let res = search_for_images_to_download(
4747
known_images,
4848
user.steam_user_data_folder.as_str(),
4949
&shortcut_info.shortcuts,
@@ -113,7 +113,7 @@ pub struct PublicGameResponse {
113113
data: Option<PublicGameResponseData>,
114114
}
115115

116-
async fn search_fo_to_download(
116+
async fn search_for_images_to_download(
117117
known_images: Vec<String>,
118118
user_data_folder: &str,
119119
shortcuts: &[ShortcutOwned],
@@ -196,36 +196,38 @@ async fn search_fo_to_download(
196196
}
197197
}
198198
} else {
199-
let image_search_result =
200-
get_images_for_ids(client, &image_ids, &image_type, download_animated).await;
201-
match image_search_result {
202-
Ok(images) => {
203-
let images = images
204-
.iter()
205-
.enumerate()
206-
.map(|(index, image)| (image, shortcuts[index], image_ids[index]));
207-
let download_for_this_type = stream::iter(images)
208-
.filter_map(|(image, shortcut, game_id)| {
209-
let path = grid_folder.join(image_type.file_name(shortcut.app_id));
210-
async move {
211-
let image_url = match image {
212-
Ok(img) => Some(img.url.clone()),
213-
Err(_) => get_steam_image_url(game_id, &image_type).await,
214-
};
215-
image_url.map(|url| ToDownload {
216-
path,
217-
url,
218-
app_name: shortcut.app_name.clone(),
219-
image_type,
220-
})
221-
}
222-
})
223-
.collect::<Vec<ToDownload>>()
224-
.await;
199+
for image_ids in image_ids.chunks(99){
200+
let image_search_result =
201+
get_images_for_ids(client, &image_ids, &image_type, download_animated).await;
202+
match image_search_result {
203+
Ok(images) => {
204+
let images = images
205+
.iter()
206+
.enumerate()
207+
.map(|(index, image)| (image, shortcuts[index], image_ids[index]));
208+
let download_for_this_type = stream::iter(images)
209+
.filter_map(|(image, shortcut, game_id)| {
210+
let path = grid_folder.join(image_type.file_name(shortcut.app_id));
211+
async move {
212+
let image_url = match image {
213+
Ok(img) => Some(img.url.clone()),
214+
Err(_) => get_steam_image_url(game_id, &image_type).await,
215+
};
216+
image_url.map(|url| ToDownload {
217+
path,
218+
url,
219+
app_name: shortcut.app_name.clone(),
220+
image_type,
221+
})
222+
}
223+
})
224+
.collect::<Vec<ToDownload>>()
225+
.await;
225226

226-
to_download.extend(download_for_this_type);
227+
to_download.extend(download_for_this_type);
228+
}
229+
Err(err) => println!("Error getting images: {}", err),
227230
}
228-
Err(err) => println!("Error getting images: {}", err),
229231
}
230232
}
231233
}

0 commit comments

Comments
 (0)