versions not correctly updated

This commit is contained in:
Quaternions 2024-01-13 22:56:12 -08:00
parent 15e8c8208f
commit 35657d4d51

View File

@ -367,6 +367,7 @@ struct DownloadHistoryConfig{
} }
async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
let mut asset_list_contents=std::collections::HashSet::new();
let mut asset_list:Vec<AssetVersion>=Vec::new(); let mut asset_list:Vec<AssetVersion>=Vec::new();
if config.end_version.is_none()&&config.continue_from_versions{ if config.end_version.is_none()&&config.continue_from_versions{
//load prexisting versions list //load prexisting versions list
@ -380,16 +381,15 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
} }
} }
//write down which versions are contained //write down which versions are contained
let mut reference_hashmap=std::collections::HashSet::new();
for asset_version in &asset_list{ for asset_version in &asset_list{
reference_hashmap.insert(asset_version.assetVersionNumber); asset_list_contents.insert(asset_version.assetVersionNumber);
} }
//find the highest number //find the highest number
match asset_list.iter().map(|asset_version|asset_version.assetVersionNumber).max(){ match asset_list.iter().map(|asset_version|asset_version.assetVersionNumber).max(){
Some(max)=>{ Some(max)=>{
//count down contiguously until a number is missing //count down contiguously until a number is missing
for i in (1..=max).rev(){ for i in (1..=max).rev(){
if !reference_hashmap.contains(&i){ if !asset_list_contents.contains(&i){
//that is end_version //that is end_version
config.end_version=Some(i); config.end_version=Some(i);
break; break;
@ -402,9 +402,6 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
}, },
None=>Err(anyhow::Error::msg("Cannot continue from versions.json - there are no previous versions"))?, None=>Err(anyhow::Error::msg("Cannot continue from versions.json - there are no previous versions"))?,
} }
//clear the asset list, I can't tell if roblox provides a way to start on a specific page
//so it just starts from the beginning every time
asset_list.clear();
} }
let client=reqwest::Client::new(); let client=reqwest::Client::new();
@ -422,18 +419,25 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
let asset_id_str=asset_id_string.clone(); let asset_id_str=asset_id_string.clone();
let output_folder=config.output_folder.clone(); let output_folder=config.output_folder.clone();
let data=&page.data; let data=&page.data;
let asset_list_contents=&asset_list_contents;
let join_set=&mut join_set; let join_set=&mut join_set;
let error_catcher=||async move{ let error_catcher=||async move{
let mut cancel_paging=false; let mut cancel_paging=false;
for asset_version in data{ for asset_version in data{
let version_number=asset_version.assetVersionNumber; let version_number=asset_version.assetVersionNumber;
//skip assets beyond specified end_version
if config.end_version.is_some_and(|v|v<version_number){ if config.end_version.is_some_and(|v|v<version_number){
continue; continue;
} }
//skip assets lower than start_version and cancel paging asset versions
if version_number<config.start_version{ if version_number<config.start_version{
cancel_paging=true; cancel_paging=true;
continue;//don't trust roblox returned order continue;//don't trust roblox returned order
} }
//skip previously downloaded assets
if asset_list_contents.contains(&version_number){
continue;
}
while CONCURRENT_REQUESTS<=join_set.len(){ while CONCURRENT_REQUESTS<=join_set.len(){
join_set.join_next().await.unwrap()??; join_set.join_next().await.unwrap()??;
} }
@ -468,7 +472,9 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
}; };
if page.nextPageCursor.is_none()||cancel_paging{ if page.nextPageCursor.is_none()||cancel_paging{
for asset_version in page.data.into_iter(){ for asset_version in page.data.into_iter(){
if config.start_version<=asset_version.assetVersionNumber{ if !(asset_list_contents.contains(&asset_version.assetVersionNumber)
||config.end_version.is_some_and(|v|v<asset_version.assetVersionNumber)
||asset_version.assetVersionNumber<config.start_version){
asset_list.push(asset_version); asset_list.push(asset_version);
} }
} }