style: cargo fmt
This commit is contained in:
@@ -646,9 +646,8 @@ pub async fn attention(State(state): State<AppState>) -> Result<Json<AttentionQu
|
||||
let needs_decision = sqlx::query_as!(Movie, r#"SELECT id AS "id!: i64", tmdb_id AS "tmdb_id!: i64", title AS "title!: String", year, original_language, root_id AS "root_id!: i64", wanted AS "wanted!: bool", overrides AS "overrides!: serde_json::Value", state AS "state!: String", blocked AS "blocked!: bool", search_attempts AS "search_attempts!: i64", last_searched_at, (SELECT f.waiver FROM media_files f WHERE f.owner_kind = 'movie' AND f.owner_id = movies.id AND f.waiver IS NOT NULL ORDER BY f.id LIMIT 1) AS "waiver?: serde_json::Value" FROM movies WHERE (SELECT count(DISTINCT g.release_id) FROM grabs g WHERE g.target_kind = 'movie' AND g.target_id = movies.id AND g.state = 'failed') >= 2 ORDER BY title"#)
|
||||
.fetch_all(pool(&state)?)
|
||||
.await?;
|
||||
let tv_no_pt_source =
|
||||
sqlx::query!(
|
||||
r#"
|
||||
let tv_no_pt_source = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.id AS "series_id!: i64", s.tmdb_id AS "tmdb_id!: i64",
|
||||
s.title AS "title!: String", s.year, e.id AS "episode_id!: i64"
|
||||
FROM episodes e
|
||||
@@ -665,9 +664,9 @@ pub async fn attention(State(state): State<AppState>) -> Result<Json<AttentionQu
|
||||
)
|
||||
ORDER BY se.number, e.number
|
||||
"#
|
||||
)
|
||||
.fetch_all(pool(&state)?)
|
||||
.await?;
|
||||
)
|
||||
.fetch_all(pool(&state)?)
|
||||
.await?;
|
||||
let episode_hard_fails = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.id AS "series_id!: i64", s.tmdb_id AS "tmdb_id!: i64",
|
||||
@@ -699,7 +698,10 @@ pub async fn attention(State(state): State<AppState>) -> Result<Json<AttentionQu
|
||||
|
||||
let mut tv_no_pt: Vec<SeriesAttention> = Vec::new();
|
||||
for row in tv_no_pt_source {
|
||||
match tv_no_pt.iter_mut().find(|entry| entry.series_id == row.series_id) {
|
||||
match tv_no_pt
|
||||
.iter_mut()
|
||||
.find(|entry| entry.series_id == row.series_id)
|
||||
{
|
||||
Some(entry) => entry.episodes.push(row.episode_id),
|
||||
None => tv_no_pt.push(SeriesAttention {
|
||||
series_id: row.series_id,
|
||||
@@ -716,7 +718,10 @@ pub async fn attention(State(state): State<AppState>) -> Result<Json<AttentionQu
|
||||
// both and is merged into one entry.
|
||||
let mut tv_needs: Vec<SeriesAttention> = Vec::new();
|
||||
for row in episode_hard_fails {
|
||||
match tv_needs.iter_mut().find(|entry| entry.series_id == row.series_id) {
|
||||
match tv_needs
|
||||
.iter_mut()
|
||||
.find(|entry| entry.series_id == row.series_id)
|
||||
{
|
||||
Some(entry) => entry.episodes.push(row.episode_id),
|
||||
None => tv_needs.push(SeriesAttention {
|
||||
series_id: row.series_id,
|
||||
@@ -729,7 +734,10 @@ pub async fn attention(State(state): State<AppState>) -> Result<Json<AttentionQu
|
||||
}
|
||||
}
|
||||
for row in season_pack_fails {
|
||||
match tv_needs.iter_mut().find(|entry| entry.series_id == row.series_id) {
|
||||
match tv_needs
|
||||
.iter_mut()
|
||||
.find(|entry| entry.series_id == row.series_id)
|
||||
{
|
||||
Some(entry) => entry.seasons.push(row.season_id),
|
||||
None => tv_needs.push(SeriesAttention {
|
||||
series_id: row.series_id,
|
||||
@@ -840,8 +848,8 @@ pub async fn untag_owner(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sqlx::Row;
|
||||
use crate::{router, Upstreams};
|
||||
use sqlx::Row;
|
||||
|
||||
async fn application() -> (tempfile::TempDir, AppState, String) {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
@@ -1322,12 +1330,13 @@ mod tests {
|
||||
.await
|
||||
.expect("series")
|
||||
.get(0);
|
||||
let season_id: i64 =
|
||||
sqlx::query_scalar("INSERT INTO seasons (series_id, number) VALUES (?, 1) RETURNING id")
|
||||
.bind(series_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.expect("season");
|
||||
let season_id: i64 = sqlx::query_scalar(
|
||||
"INSERT INTO seasons (series_id, number) VALUES (?, 1) RETURNING id",
|
||||
)
|
||||
.bind(series_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.expect("season");
|
||||
|
||||
// Two wanted episodes whose every candidate was rejected for
|
||||
// language — the §5.2 no-PT-source queue, TV side.
|
||||
@@ -1379,7 +1388,11 @@ mod tests {
|
||||
)
|
||||
.bind(release_id)
|
||||
.bind(kind)
|
||||
.bind(if kind == "season" { season_id } else { episode_id })
|
||||
.bind(if kind == "season" {
|
||||
season_id
|
||||
} else {
|
||||
episode_id
|
||||
})
|
||||
.bind(format!("hash-{suffix}"))
|
||||
.execute(pool)
|
||||
.await
|
||||
@@ -1404,7 +1417,10 @@ mod tests {
|
||||
queues["tv_needs_decision"][0]["episodes"],
|
||||
serde_json::json!([episode_id])
|
||||
);
|
||||
assert_eq!(queues["tv_needs_decision"][0]["seasons"], serde_json::json!([season_id]));
|
||||
assert_eq!(
|
||||
queues["tv_needs_decision"][0]["seasons"],
|
||||
serde_json::json!([season_id])
|
||||
);
|
||||
|
||||
// Blocking the series empties its no-PT-source lane.
|
||||
sqlx::query("UPDATE series SET blocked = 1 WHERE id = ?")
|
||||
@@ -1418,10 +1434,7 @@ mod tests {
|
||||
.json()
|
||||
.await
|
||||
.expect("blocked queues json");
|
||||
assert_eq!(
|
||||
queues["tv_no_pt_source"].as_array().map(Vec::len),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(queues["tv_no_pt_source"].as_array().map(Vec::len), Some(0));
|
||||
assert_eq!(
|
||||
queues["tv_needs_decision"].as_array().map(Vec::len),
|
||||
Some(1),
|
||||
|
||||
@@ -317,28 +317,25 @@ mod tests {
|
||||
/// A series on the kids TV root with one season, and `count` wanted,
|
||||
/// missing episodes that have been searched. No stored releases: every
|
||||
/// candidate was rejected for language (§5.2's no-PT-source case).
|
||||
async fn insert_no_pt_source_series(
|
||||
database: &Db,
|
||||
tmdb_id: i64,
|
||||
episode_count: usize,
|
||||
) -> i64 {
|
||||
async fn insert_no_pt_source_series(database: &Db, tmdb_id: i64, episode_count: usize) -> i64 {
|
||||
let root_id: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM roots WHERE kind = 'tv' AND audience = 'kids'")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query("INSERT INTO series (tmdb_id, title, year, root_id) VALUES (?, 'Bluey', 2018, ?)")
|
||||
sqlx::query(
|
||||
"INSERT INTO series (tmdb_id, title, year, root_id) VALUES (?, 'Bluey', 2018, ?)",
|
||||
)
|
||||
.bind(tmdb_id)
|
||||
.bind(root_id)
|
||||
.execute(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
let series_id: i64 = sqlx::query_scalar("SELECT id FROM series WHERE tmdb_id = ?")
|
||||
.bind(tmdb_id)
|
||||
.bind(root_id)
|
||||
.execute(database.pool())
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
let series_id: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM series WHERE tmdb_id = ?")
|
||||
.bind(tmdb_id)
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query("INSERT INTO seasons (series_id, number) VALUES (?, 1)")
|
||||
.bind(series_id)
|
||||
.execute(database.pool())
|
||||
@@ -510,11 +507,10 @@ mod tests {
|
||||
async fn an_episode_hard_failed_twice_notifies_its_series() {
|
||||
let (_dir, database) = seeded_database().await;
|
||||
insert_no_pt_source_series(&database, 1, 0).await;
|
||||
let season_id: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM seasons WHERE number = 1")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
let season_id: i64 = sqlx::query_scalar("SELECT id FROM seasons WHERE number = 1")
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query(
|
||||
"INSERT INTO episodes (season_id, number, title, wanted, state)
|
||||
VALUES (?, 1, 'Episode 0', 1, 'missing')",
|
||||
@@ -523,13 +519,12 @@ mod tests {
|
||||
.execute(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
let episode_id: i64 = sqlx::query_scalar(
|
||||
"SELECT id FROM episodes WHERE season_id = ? AND number = 1",
|
||||
)
|
||||
.bind(season_id)
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
let episode_id: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM episodes WHERE season_id = ? AND number = 1")
|
||||
.bind(season_id)
|
||||
.fetch_one(database.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
insert_failed_grab(&database, "episode", episode_id, "first").await;
|
||||
insert_failed_grab(&database, "episode", episode_id, "second").await;
|
||||
// The pack's failure sent this season back to per-episode grabbing;
|
||||
|
||||
Reference in New Issue
Block a user