Update library lists when a move finishes (#1)
CI / test (push) Successful in 1m14s

The Library now follows moves on both servers: an item shows "Moving to …" while it moves and "Moved to …" until the source's Jellyfin drops
it after its rescan; the list reloads when a move finishes and checks again every 20 s for a few minutes. The destination shows the new item
straight away.
This commit is contained in:
IxianPixel committed 2026-11-06 17:21:22 +00:00
1 parent 484ac50508
commit 2bd4489b1a
9 files changed
+236 -61

No files matched your search

+2
View File
@@ -484,6 +484,8 @@ pub async fn complete(state: &Shared, id: &str, req: CompleteRequest) -> anyhow:
}
}
// After a season move the show is still listed here, but smaller.
crate::sizes::forget(state, &local_folder).await;
if let Err(e) = state
.jellyfin
.media_updated(std::slice::from_ref(&export.jellyfin_folder))
+2
View File
@@ -347,6 +347,8 @@ async fn promote(state: &Shared, job: &mut Job) -> anyhow::Result<()> {
Some(season) => target_local.join(&season.folder),
None => target_local.clone(),
};
// A season changes the size of a show that may already be listed here.
crate::sizes::forget(state, &target_local).await;
job.note(format!("moved into {}", placed.display()));
job.advance(Stage::Promoted);
Ok(())
+9 -1
View File
@@ -20,7 +20,7 @@ use std::sync::Mutex;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use crate::state::Shared;
use crate::state::{AppState, Shared};
/// How often a cached size's signature is checked against the disk.
pub const RECHECK: time::Duration = time::Duration::hours(1);
@@ -151,6 +151,14 @@ async fn refresh(state: &Shared, folder: &Path) -> anyhow::Result<()> {
Ok(())
}
/// Drop the cached size of a folder a move has just changed, so the next
/// listing measures it again instead of waiting for the hourly check.
pub async fn forget(state: &AppState, folder: &Path) {
if let Err(e) = state.store.delete_folder_size(&key(folder)).await {
tracing::warn!(folder = %folder.display(), error = %e, "could not forget folder size");
}
}
fn key(p: &Path) -> String {
p.to_string_lossy().into_owned()
}
+14
View File
@@ -589,6 +589,9 @@ async fn moves_seasons_one_at_a_time_and_trashes_the_empty_show() {
assert_eq!(seasons[0]["folder"], "Season 01");
assert_eq!(seasons[1]["number"], 2);
// List cloud's shows first so their sizes are cached.
items_with_sizes(&cloud.url, "node=local&library=lib-tv-shows").await;
// Season 2 into a show home doesn't have yet: the show's NFO comes too.
let s2 = cloud.fake.season_id("Severance", 2).unwrap();
assert_eq!(seasons[1]["id"], s2);
@@ -612,8 +615,15 @@ async fn moves_seasons_one_at_a_time_and_trashes_the_empty_show() {
let home_series = home.fake.find("Series", "Severance").unwrap();
assert!(home.fake.get_user_data(&home_series).is_none());
// The cached size of cloud's show was dropped, so it's measured again
// without waiting for the hourly check.
let shows = items_with_sizes(&cloud.url, "node=local&library=lib-tv-shows").await;
assert_eq!(shows[0]["size"]["bytes"], tree_size(&show_cloud));
assert_eq!(shows[0]["size"]["parts"].as_array().unwrap().len(), 1);
// Mark home's copy of the NFO so we can tell it isn't overwritten.
std::fs::write(show_home.join("tvshow.nfo"), b"home's own").unwrap();
items_with_sizes(&home.url, "node=local&library=lib-tv-shows").await;
// Season 1 joins the existing show, and was the last one on cloud.
let s1 = cloud.fake.season_id("Severance", 1).unwrap();
@@ -628,6 +638,10 @@ async fn moves_seasons_one_at_a_time_and_trashes_the_empty_show() {
);
assert!(show_home.join("Season 01/Severance S01E02.mkv").exists());
assert_eq!(std::fs::read(show_home.join("tvshow.nfo")).unwrap(), b"home's own");
// Home's show grew, and its size says so straight away.
let shows = items_with_sizes(&home.url, "node=local&library=lib-tv-shows").await;
assert_eq!(shows[0]["size"]["bytes"], tree_size(&show_home));
assert_eq!(shows[0]["size"]["parts"].as_array().unwrap().len(), 2);
let new_e1 = home.fake.episode_id("Severance", 1, 1).unwrap();
assert_eq!(home.fake.get_user_data(&new_e1).unwrap()["Played"], true);