perf: implement smart merge logic for FullList to preserve reactive references
All checks were successful
Build MIPS Binary / build (push) Successful in 4m22s

This commit is contained in:
spinline
2026-02-09 00:40:09 +03:00
parent afdc34e131
commit 5a8f5169ea

View File

@@ -195,11 +195,26 @@ pub fn provide_torrent_store() {
if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) { if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) {
match event { match event {
AppEvent::FullList { torrents: list, .. } => { AppEvent::FullList { torrents: list, .. } => {
let map: HashMap<String, Torrent> = list torrents.update(|map| {
.into_iter() // 1. Create a set of new hashes for quick lookup
.map(|t| (t.hash.clone(), t)) let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
.collect();
torrents.set(map); // 2. Remove torrents that are no longer in the list
map.retain(|hash, _| new_hashes.contains(hash));
// 3. Update or Insert torrents from the new list
for new_torrent in list {
if let Some(existing) = map.get_mut(&new_torrent.hash) {
// Only update if changed (Torrent derives PartialEq)
if existing != &new_torrent {
*existing = new_torrent;
}
} else {
// New torrent, insert it
map.insert(new_torrent.hash.clone(), new_torrent);
}
}
});
} }
AppEvent::Update(update) => { AppEvent::Update(update) => {
torrents.update(|map| { torrents.update(|map| {