Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions rustatio-core/src/faker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,31 @@ impl RatioFaker {
.map_err(|e| FakerError::ConfigError(e.to_string()))?;
}

// Recompute left/torrent_completion from the new completion_percent.
// This ensures that changing completion_percent in the UI takes effect
// without having to recreate the faker.
let completion = config.completion_percent.clamp(0.0, 100.0) / 100.0;
let torrent_downloaded = (self.torrent.total_size as f64 * completion) as u64;
let new_left = self.torrent.total_size.saturating_sub(torrent_downloaded);
let new_torrent_completion = if self.torrent.total_size > 0 {
((self.torrent.total_size - new_left) as f64 / self.torrent.total_size as f64) * 100.0
} else {
100.0
};

#[cfg(not(target_arch = "wasm32"))]
if let Ok(mut stats) = self.stats.try_write() {
stats.left = new_left;
stats.torrent_completion = new_torrent_completion;
}

#[cfg(target_arch = "wasm32")]
{
let mut stats = self.stats.borrow_mut();
stats.left = new_left;
stats.torrent_completion = new_torrent_completion;
}

self.config = config;
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions rustatio-desktop/src/commands/faker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ pub async fn start_faker(
if existing.torrent.info_hash == torrent_info_hash {
config_with_cumulative.initial_uploaded = existing.cumulative_uploaded;
config_with_cumulative.initial_downloaded = existing.cumulative_downloaded;
let existing_stats = existing.faker.read().await.get_stats().await;
config_with_cumulative.completion_percent = existing_stats.torrent_completion;
log_and_emit!(
&app,
instance_id,
info,
"Same torrent detected - continuing with cumulative stats: uploaded={} bytes, downloaded={} bytes, completion={:.1}%",
existing.cumulative_uploaded,
existing.cumulative_downloaded,
existing_stats.torrent_completion
config_with_cumulative.completion_percent
);
} else {
log_and_emit!(
Expand Down
4 changes: 0 additions & 4 deletions rustatio-desktop/src/commands/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ pub async fn grid_update_config(
let mut new_config = faker_config.clone();
new_config.initial_uploaded = instance.cumulative_uploaded;
new_config.initial_downloaded = instance.cumulative_downloaded;
let existing_stats = instance.faker.read().await.get_stats().await;
new_config.completion_percent = existing_stats.torrent_completion;

let result = instance
.faker
Expand Down Expand Up @@ -551,8 +549,6 @@ pub async fn bulk_update_configs(
let mut new_config = entry.config.clone();
new_config.initial_uploaded = instance.cumulative_uploaded;
new_config.initial_downloaded = instance.cumulative_downloaded;
let existing_stats = instance.faker.read().await.get_stats().await;
new_config.completion_percent = existing_stats.torrent_completion;

let result = instance
.faker
Expand Down
14 changes: 0 additions & 14 deletions rustatio-server/src/services/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@ impl AppState {
let mut faker_config = config.clone();
faker_config.initial_uploaded = instance.cumulative_uploaded;
faker_config.initial_downloaded = instance.cumulative_downloaded;
let existing_stats = instance
.faker
.read()
.await
.stats_snapshot()
.unwrap_or_else(|| RatioFaker::stats_from_config(&instance.config));
faker_config.completion_percent = existing_stats.torrent_completion;

instance
.faker
Expand Down Expand Up @@ -274,13 +267,6 @@ impl AppState {
let mut faker_config = config.clone();
faker_config.initial_uploaded = instance.cumulative_uploaded;
faker_config.initial_downloaded = instance.cumulative_downloaded;
let existing_stats = instance
.faker
.read()
.await
.stats_snapshot()
.unwrap_or_else(|| RatioFaker::stats_from_config(&instance.config));
faker_config.completion_percent = existing_stats.torrent_completion;

let result = instance
.faker
Expand Down