fix(web): count on-disk episodes, not just wanted
Untracking a season clears `wanted` on every episode (§4.1) and leaves the files where they were, so a season grabbed once and then untracked rendered `0/0 eps` beside a column of green check glyphs. The same counter could also read `10/1`, since the numerator was drawn from the wanted set the denominator had already shrunk. An episode now counts once it is wanted, on disk, or both, and the chip is hidden rather than shown as `0/0` when a season or series accounts for nothing. `Series.wanted_episodes` becomes `total_episodes`.
This commit is contained in:
@@ -65,9 +65,11 @@ pub struct Series {
|
||||
pub metadata_refreshed_at: Option<String>,
|
||||
/// `airing`, `incomplete`, `waiting`, `complete` or `ended` (§4.2).
|
||||
pub status: String,
|
||||
/// Episodes currently marked wanted (§4.1 — the only intent).
|
||||
pub wanted_episodes: i64,
|
||||
/// Wanted episodes already on disk.
|
||||
/// Episodes this series accounts for: wanted, on disk, or both (§4.1).
|
||||
/// A season grabbed once and then untracked keeps its files counted —
|
||||
/// nothing wanted is not the same as nothing there.
|
||||
pub total_episodes: i64,
|
||||
/// Counted episodes already on disk.
|
||||
pub available_episodes: i64,
|
||||
}
|
||||
|
||||
@@ -317,10 +319,15 @@ fn with_status(row: &SeriesRow, episodes: &[arr_core::Episode], now: SystemTime)
|
||||
// too. A series reading `complete` next to `42/52 eps` is the confusion
|
||||
// this avoids. The season number rides on each episode (#131), so no
|
||||
// parallel slice can be forgotten.
|
||||
let wanted = episodes
|
||||
.iter()
|
||||
.filter(|episode| episode.wanted && episode.season_number != 0);
|
||||
let available = wanted
|
||||
//
|
||||
// The denominator is wanted-or-on-disk, not wanted alone. Untracking a
|
||||
// season clears `wanted` on every episode (§4.1) while the files stay,
|
||||
// so counting intent alone reads `0/0 eps` next to a season of green
|
||||
// check glyphs.
|
||||
let counted = episodes.iter().filter(|episode| {
|
||||
episode.season_number != 0 && (episode.wanted || episode.state == MediaState::Available)
|
||||
});
|
||||
let available = counted
|
||||
.clone()
|
||||
.filter(|episode| episode.state == MediaState::Available);
|
||||
Series {
|
||||
@@ -339,7 +346,7 @@ fn with_status(row: &SeriesRow, episodes: &[arr_core::Episode], now: SystemTime)
|
||||
vote_average: row.vote_average,
|
||||
metadata_refreshed_at: row.metadata_refreshed_at.clone(),
|
||||
status: status_name(derive_series_status(&core_series(row), episodes, now)).to_owned(),
|
||||
wanted_episodes: i64::try_from(wanted.count()).unwrap_or(i64::MAX),
|
||||
total_episodes: i64::try_from(counted.count()).unwrap_or(i64::MAX),
|
||||
available_episodes: i64::try_from(available.count()).unwrap_or(i64::MAX),
|
||||
}
|
||||
}
|
||||
@@ -3109,7 +3116,7 @@ mod tests {
|
||||
listed[0]["status"], "incomplete",
|
||||
"§4.2: an aired wanted episode with no file"
|
||||
);
|
||||
assert_eq!(listed[0]["wanted_episodes"], 1);
|
||||
assert_eq!(listed[0]["total_episodes"], 1);
|
||||
assert_eq!(listed[0]["available_episodes"], 0);
|
||||
|
||||
sqlx::query("UPDATE episodes SET state = 'available' WHERE id = ?")
|
||||
|
||||
Reference in New Issue
Block a user