Skip to content

Commit 64fc2b9

Browse files
authored
fix: modpack data is invalid when bulk updating (#7773)
Fixes #7733
1 parent 4c0fcf0 commit 64fc2b9

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

‎packages/app-lib/src/state/instances/commands/apply_content_update.rs‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::state::instances::{
88
adapters::sqlite::{content_rows, instance_rows},
99
};
1010
use crate::state::{
11-
CacheBehaviour, CachedEntry, Dependency, DependencyType, State, Version,
11+
CacheBehaviour, CachedEntry, CachedFile, Dependency, DependencyType, State,
12+
Version,
1213
};
1314
use crate::util::fetch::DownloadReason;
1415
use futures::stream::{self, StreamExt};
@@ -609,30 +610,54 @@ async fn installed_projects(
609610
.collect::<HashMap<_, _>>();
610611
let files =
611612
content_rows::get_instance_files(&instance.id, &state.pool).await?;
613+
let hashes = files
614+
.iter()
615+
.map(|file| file.sha1.as_str())
616+
.collect::<Vec<_>>();
617+
let file_info = CachedEntry::get_file_many(
618+
&hashes,
619+
Some(CacheBehaviour::MustRevalidate),
620+
&state.pool,
621+
&state.api_semaphore,
622+
)
623+
.await?;
624+
let file_info_by_hash = file_info
625+
.into_iter()
626+
.map(|file| (file.hash.clone(), file))
627+
.collect::<HashMap<_, _>>();
612628

613629
Ok(files
614630
.into_iter()
615631
.filter_map(|file| {
616-
let entry = entries_by_file_id.get(file.id.as_str())?;
617-
installed_project_from_row(&file, entry)
632+
let entry = entries_by_file_id.get(file.id.as_str()).copied();
633+
let metadata = file_info_by_hash.get(&file.sha1);
634+
installed_project_from_row(&file, entry, metadata)
618635
})
619636
.collect())
620637
}
621638

622639
fn installed_project_from_row(
623640
file: &InstanceFile,
624-
entry: &ContentEntry,
641+
entry: Option<&ContentEntry>,
642+
cached: Option<&CachedFile>,
625643
) -> Option<InstalledProject> {
626-
if entry.project_id.is_none() && entry.version_id.is_none() {
644+
let project_id = entry
645+
.and_then(|entry| entry.project_id.clone())
646+
.or_else(|| cached.map(|file| file.project_id.clone()));
647+
let version_id = entry
648+
.and_then(|entry| entry.version_id.clone())
649+
.or_else(|| cached.map(|file| file.version_id.clone()));
650+
if project_id.is_none() && version_id.is_none() {
627651
return None;
628652
}
629653

630654
Some(InstalledProject {
631655
relative_path: file.relative_path.clone(),
632-
project_id: entry.project_id.clone(),
633-
version_id: entry.version_id.clone(),
634-
source_kind: entry.source_kind,
635-
enabled: entry.enabled && file.enabled,
656+
project_id,
657+
version_id,
658+
source_kind: entry
659+
.map_or(ContentSourceKind::Local, |entry| entry.source_kind),
660+
enabled: entry.is_none_or(|entry| entry.enabled) && file.enabled,
636661
})
637662
}
638663

0 commit comments

Comments
 (0)