Show folder sizes for movies, shows and seasons. Closes #5
CI / test (push) Successful in 1m12s
CI / test (push) Successful in 1m12s
The library lists now show how much space each movie and show takes on disk, counting everything a move copies, with a per-season breakdown for shows, a running total and a "Largest first" sort. - sizes.rs: a single background worker measures one folder at a time. Listing returns cached sizes straight away and queues folders; the UI polls until every size has arrived. - Cached in a new folder_sizes table (store migration v2). A size is kept while the folder's signature (mtimes of the folder and its direct subfolders) is unchanged, checked at most hourly and re-measured after 7 days. - Each agent measures its own folders, so peer listings carry the peer's sizes. - Tests for measuring, signatures, natural season order, the migration, and an e2e test covering both sides and a moved item.
This commit is contained in:
1 parent
4c6217bd40
commit
25a743b350
11 files changed
+672
-26
No files matched your search
@@ -517,6 +517,56 @@ async fn an_item_moved_away_twice_gets_two_trash_entries() {
|
||||
assert_eq!(home_trash[0]["moved_to"], "cloud");
|
||||
}
|
||||
|
||||
/// List a library until every item has a size, like the UI does.
|
||||
async fn items_with_sizes(base: &str, query: &str) -> Vec<Value> {
|
||||
let deadline = Instant::now() + Duration::from_secs(30);
|
||||
loop {
|
||||
let items = get(base, &format!("/api/items?{query}")).await;
|
||||
let items = items.as_array().unwrap().clone();
|
||||
if !items.is_empty() && items.iter().all(|i| i["size"].is_object()) {
|
||||
return items;
|
||||
}
|
||||
assert!(Instant::now() < deadline, "sizes never arrived: {items:#?}");
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn lists_folder_sizes_for_movies_shows_and_seasons() {
|
||||
let (cloud, home) = pair(|root| {
|
||||
seed_movie(root);
|
||||
seed_series(root);
|
||||
})
|
||||
.await;
|
||||
|
||||
// A movie's size is its whole folder: video, subtitles, NFO and extras.
|
||||
let movies = items_with_sizes(&cloud.url, "node=local&library=lib-movies").await;
|
||||
let alien = &movies[0]["size"];
|
||||
assert_eq!(alien["bytes"], tree_size(&cloud.movies().join("Alien (1979)")));
|
||||
assert_eq!(alien["files"], 4);
|
||||
|
||||
// A show has a total plus one part per season folder; loose files such
|
||||
// as tvshow.nfo count towards the total only.
|
||||
let shows = items_with_sizes(&home.url, "node=peer&library=lib-tv-shows").await;
|
||||
let s = &shows[0]["size"];
|
||||
assert_eq!(shows[0]["name"], "Severance");
|
||||
assert_eq!(s["bytes"], tree_size(&cloud.tv().join("Severance")));
|
||||
assert_eq!(s["files"], 4);
|
||||
assert_eq!(
|
||||
s["parts"],
|
||||
json!([
|
||||
{"name": "Season 01", "bytes": 22, "files": 2},
|
||||
{"name": "Season 02", "bytes": 13, "files": 1},
|
||||
])
|
||||
);
|
||||
|
||||
// After a move the item is measured where it now lives.
|
||||
let movie = cloud.fake.find("Movie", "Alien").unwrap();
|
||||
move_item(&cloud.url, "local", &movie, "Alien").await;
|
||||
let on_home = items_with_sizes(&home.url, "node=local&library=lib-movies").await;
|
||||
assert_eq!(on_home[0]["size"], *alien);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn peer_api_rejects_bad_token_and_ui_requires_csrf_header() {
|
||||
let (cloud, _home) = pair(|_| {}).await;
|
||||
|
||||
Reference in new issue
Block a user