fix(meta): store unrated titles as NULL, not zero
TMDB reports vote_average: 0 where no rating exists (#156). Normalise it to None at the arr-meta edge, like non_empty does for "", and let the Option flow through the daemon refresh and API add paths so the nullable columns from #145 do their job.
This commit is contained in:
@@ -2497,6 +2497,81 @@ mod tests {
|
||||
assert_eq!(unchanged, (poster, backdrop, vote));
|
||||
}
|
||||
|
||||
/// TMDB reports `vote_average: 0` for a title nobody has rated — absence,
|
||||
/// not zero (#156). It must store as NULL, be overwritten when votes
|
||||
/// arrive, and go back to NULL if they are withdrawn.
|
||||
#[tokio::test]
|
||||
async fn metadata_refresh_stores_an_unrated_title_as_null() {
|
||||
let (_dir, database) = wanted_movie().await;
|
||||
let indexer = empty_prowlarr().await;
|
||||
let unrated = || {
|
||||
RELEASED_METADATA.replace(
|
||||
r#""original_language": "en","#,
|
||||
r#""original_language": "en",
|
||||
"poster_path": "/dune-two.jpg",
|
||||
"backdrop_path": "/dune-two-wide.jpg",
|
||||
"vote_average": 0.0,"#,
|
||||
)
|
||||
};
|
||||
let rated = || {
|
||||
RELEASED_METADATA.replace(
|
||||
r#""original_language": "en","#,
|
||||
r#""original_language": "en",
|
||||
"poster_path": "/dune-two.jpg",
|
||||
"backdrop_path": "/dune-two-wide.jpg",
|
||||
"vote_average": 8.152,"#,
|
||||
)
|
||||
};
|
||||
let (downloader, _fake) = transmission().await;
|
||||
|
||||
action_with_tmdb(&indexer, &downloader, &tmdb(&unrated()).await)
|
||||
.tick(&database)
|
||||
.await
|
||||
.unwrap();
|
||||
let vote: Option<f64> =
|
||||
sqlx::query_scalar("SELECT vote_average FROM movies WHERE tmdb_id IS NOT NULL")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(vote, None);
|
||||
|
||||
// Votes arrive: the NULL is overwritten.
|
||||
sqlx::query(
|
||||
"UPDATE movies SET metadata_refreshed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now', '-7 hours')",
|
||||
)
|
||||
.execute(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
action_with_tmdb(&indexer, &downloader, &tmdb(&rated()).await)
|
||||
.tick(&database)
|
||||
.await
|
||||
.unwrap();
|
||||
let vote: Option<f64> =
|
||||
sqlx::query_scalar("SELECT vote_average FROM movies WHERE tmdb_id IS NOT NULL")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(vote, Some(8.152));
|
||||
|
||||
// And withdrawn again.
|
||||
sqlx::query(
|
||||
"UPDATE movies SET metadata_refreshed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now', '-7 hours')",
|
||||
)
|
||||
.execute(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
action_with_tmdb(&indexer, &downloader, &tmdb(&unrated()).await)
|
||||
.tick(&database)
|
||||
.await
|
||||
.unwrap();
|
||||
let vote: Option<f64> =
|
||||
sqlx::query_scalar("SELECT vote_average FROM movies WHERE tmdb_id IS NOT NULL")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(vote, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn metadata_changes_reset_a_title_backoff() {
|
||||
let (_dir, database) = wanted_movie().await;
|
||||
|
||||
@@ -232,7 +232,7 @@ impl SeriesRefreshAction {
|
||||
let backdrop_path_ref = backdrop_path.as_deref();
|
||||
let artwork_moved =
|
||||
stale.poster_path != poster_path || stale.backdrop_path != backdrop_path;
|
||||
if artwork_moved || stale.vote_average != Some(vote_average) {
|
||||
if artwork_moved || stale.vote_average != vote_average {
|
||||
sqlx::query!(
|
||||
"UPDATE series SET poster_path = ?, backdrop_path = ?, vote_average = ?,
|
||||
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
||||
|
||||
Reference in New Issue
Block a user