diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-03-07 19:54:21 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-03-07 19:54:21 +0100 |
commit | 07db485f9c5206fbcfe2a5f9db28a9587edc6d2b (patch) | |
tree | 07b0b484f8a4244f38b921fcf83e60aba0f27c19 | |
parent | chore(version): v1.5.0 (diff) | |
download | yt-07db485f9c5206fbcfe2a5f9db28a9587edc6d2b.zip |
fix(yt/storage/video_database/set): Reset the `is_focused` flag
Diffstat (limited to '')
-rw-r--r-- | yt/src/storage/video_database/set/mod.rs | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/yt/src/storage/video_database/set/mod.rs b/yt/src/storage/video_database/set/mod.rs index 4006fde..3d68ce8 100644 --- a/yt/src/storage/video_database/set/mod.rs +++ b/yt/src/storage/video_database/set/mod.rs @@ -56,7 +56,7 @@ pub async fn video_status( }; let old_marker = old.status.as_marker(); - let cache_path = { + let (cache_path, is_focused) = { fn cache_path_to_string(path: &Path) -> Result<String> { Ok(path .to_str() @@ -69,13 +69,14 @@ pub async fn video_status( .to_owned()) } - match (old_marker, &new_status) { - (VideoStatusMarker::Cached, VideoStatus::Cached { cache_path, .. }) => { - Some(cache_path_to_string(cache_path)?) - } - (_, VideoStatus::Cached { cache_path, .. }) => Some(cache_path_to_string(cache_path)?), - - (VideoStatusMarker::Cached | _, _) => None, + if let VideoStatus::Cached { + cache_path, + is_focused, + } = &new_status + { + (Some(cache_path_to_string(cache_path)?), *is_focused) + } else { + (None, false) } }; @@ -98,13 +99,14 @@ pub async fn video_status( query!( r#" UPDATE videos - SET status = ?, last_status_change = ?, priority = ?, cache_path = ? + SET status = ?, last_status_change = ?, priority = ?, cache_path = ?, is_focused = ? WHERE extractor_hash = ?; "#, new_status, now, new_priority, cache_path, + is_focused, video_hash ) .execute(&app.database) @@ -125,12 +127,13 @@ pub async fn video_status( query!( r#" UPDATE videos - SET status = ?, last_status_change = ?, cache_path = ? + SET status = ?, last_status_change = ?, cache_path = ?, is_focused = ? WHERE extractor_hash = ?; "#, new_status, now, cache_path, + is_focused, video_hash ) .execute(&app.database) @@ -147,10 +150,9 @@ pub async fn video_status( /// # Panics /// Only if assertions fail. pub async fn video_watched(app: &App, video: &ExtractorHash) -> Result<()> { - let video_hash = video.hash().to_string(); - let new_status = VideoStatusMarker::Watched.as_db_integer(); - let old = { + let video_hash = video.hash().to_string(); + let base = query!( r#" SELECT * @@ -175,20 +177,7 @@ pub async fn video_watched(app: &App, video: &ExtractorHash) -> Result<()> { unreachable!("The video must be marked as Cached before it can be marked Watched"); } - let now = Utc::now().timestamp(); - - query!( - r#" - UPDATE videos - SET status = ?, last_status_change = ?, cache_path = NULL - WHERE extractor_hash = ?; - "#, - new_status, - now, - video_hash - ) - .execute(&app.database) - .await?; + video_status(app, video, VideoStatus::Watched, None).await?; Ok(()) } |