Show folder sizes for movies, shows and seasons. Closes #5
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:
IxianPixel committed 2026-11-06 16:43:52 +00:00
1 parent 4c6217bd40
commit 25a743b350
11 files changed
+672 -26

No files matched your search

+37 -5
View File
@@ -1,11 +1,12 @@
//! Browsing the local Jellyfin libraries.
use std::path::Path;
use std::path::{Path, PathBuf};
use jm_jellyfin::ItemQuery;
use serde::{Deserialize, Serialize};
use crate::state::AppState;
use crate::sizes::{self, FolderSize};
use crate::state::{AppState, Shared};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Library {
@@ -23,6 +24,9 @@ pub struct LibraryItem {
pub kind: String,
pub year: Option<i32>,
pub path: Option<String>,
/// Size of the item's folder on disk; `None` until it has been measured.
#[serde(default)]
pub size: Option<FolderSize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -55,8 +59,10 @@ pub async fn libraries(state: &AppState) -> anyhow::Result<Vec<Library>> {
.collect())
}
/// The movies and series in a library, with the size of each one's folder if
/// it's known yet. Sizes still missing are being measured in the background.
pub async fn items(
state: &AppState,
state: &Shared,
library_id: &str,
search: Option<&str>,
) -> anyhow::Result<Vec<LibraryItem>> {
@@ -71,7 +77,7 @@ pub async fn items(
..Default::default()
})
.await?;
Ok(items
let mut out: Vec<LibraryItem> = items
.into_iter()
.map(|i| LibraryItem {
id: i.id,
@@ -79,8 +85,34 @@ pub async fn items(
kind: i.kind,
year: i.production_year,
path: i.path,
size: None,
})
.collect())
.collect();
// Only items whose folder we can place are measured.
let folders: Vec<(usize, PathBuf)> = out
.iter()
.enumerate()
.filter_map(|(n, i)| Some((n, item_folder(state, i)?)))
.collect();
let paths: Vec<PathBuf> = folders.iter().map(|(_, p)| p.clone()).collect();
let sizes = sizes::lookup(state, &paths).await?;
for ((n, _), size) in folders.into_iter().zip(sizes) {
out[n].size = size;
}
Ok(out)
}
/// The folder a move would take, as this agent sees it: a movie's parent
/// folder, or the series folder itself.
fn item_folder(state: &AppState, item: &LibraryItem) -> Option<PathBuf> {
let path = Path::new(item.path.as_deref()?);
let folder = match item.kind.as_str() {
"Movie" => path.parent()?,
"Series" => path,
_ => return None,
};
Some(state.cfg.path_map.to_local(folder))
}
/// Confirm every library location exists and is writable from this agent.