diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md index 73937cc..4343dfe 100644 --- a/crates/ipx/CHANGELOG.md +++ b/crates/ipx/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- An episode's chapters, from the chapters file its feed names (``) or else from the downloaded file itself, at `GET /api/enclosures/{id}/chapters`, in the clock of DeadAir's shortened copy when that is what plays (#477). +- An episode's chapters, from the chapters file its feed names (``) or else from the downloaded file itself, at `GET /api/enclosures/{id}/chapters`, in the clock of DeadAir's shortened copy when that is what plays; episodes already out pick theirs up at the next scan (#477). - `GET /api/feeds/{id}/seasons` gives a podcast's seasons with how many episodes and unread each has, and a podcast's episodes can be asked for one season at a time, or for those naming none (`season=none`), and in its own order (`sort=episode`), season by season and episode by episode. `download-latest` takes a `season` to download all of it, first episode first (#482). - Smart playlists: `GET` and `POST /api/playlists`, `PATCH` and `DELETE /api/playlists/{id}`, and `GET /api/playlists/{id}/entries`, the episodes of the podcasts chosen in the playlist's order, those set to play first ahead of the rest (#476). - A feed in `/api/feeds` says whether it has audio or video (`podcast`), for the page's Podcasts shelf (#474). diff --git a/crates/ipx/src/db.rs b/crates/ipx/src/db.rs index 307d18c..23fe7b9 100644 --- a/crates/ipx/src/db.rs +++ b/crates/ipx/src/db.rs @@ -121,17 +121,22 @@ async fn create_missing(orm: &DatabaseConnection) -> Result<()> { .await .context("adding entries.markdown")?; } - if orm.execute_unprepared("SELECT chapters FROM entries LIMIT 0").await.is_err() { - // Stored items get theirs as a scan finds them told differently, by this alone (#477). - orm.execute_unprepared("ALTER TABLE entries ADD COLUMN chapters TEXT") - .await - .context("adding entries.chapters")?; - } if orm.execute_unprepared("SELECT body_hash FROM feeds LIMIT 0").await.is_err() { for sql in ["ALTER TABLE feeds ADD COLUMN body_hash TEXT", "ALTER TABLE feeds ADD COLUMN same_since BIGINT"] { orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?; } } + if orm.execute_unprepared("SELECT chapters FROM entries LIMIT 0").await.is_err() { + // Stored items get theirs as a scan finds them told differently, by this alone (#477); + // forgetting how each feed was last seen makes its next read a whole one, so the episodes + // out now have their chapters before their podcast next publishes. + for sql in [ + "ALTER TABLE entries ADD COLUMN chapters TEXT", + "UPDATE feeds SET etag = NULL, last_modified = NULL, body_hash = NULL", + ] { + orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?; + } + } if orm.execute_unprepared("SELECT typesafe_key FROM users LIMIT 0").await.is_err() { let sql = "ALTER TABLE users ADD COLUMN typesafe_key TEXT"; orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?; @@ -3821,6 +3826,25 @@ mod tests { assert_eq!(db.http_state("f").await.unwrap().etag.as_deref(), Some("\"b\"")); } + #[tokio::test] + async fn a_database_from_before_chapters_gains_them_and_reads_every_feed_whole() { + let db = Db::memory().await.unwrap(); + db.record_feed("f", "https://x/f", Some("F"), None, None, None, None, None, None).await.unwrap(); + db.set_body("f", "abc").await.unwrap(); + // A database from before #477. + db.exec_for_test("ALTER TABLE entries DROP COLUMN chapters").await.unwrap(); + create_missing(&db.orm).await.unwrap(); + assert_eq!(db.http_state("f").await.unwrap().body_hash, None, "read whole, so stored items get theirs"); + let e = + crate::feed::Entry { guid: "g".into(), chapters: Some("https://x/g.json".into()), ..Default::default() }; + db.record_entry("f", &e).await.unwrap(); + assert_eq!(db.chapters_url("f", "g").await.unwrap().as_deref(), Some("https://x/g.json")); + // Opened again with nothing missing, it forgets nothing. + db.set_body("f", "def").await.unwrap(); + create_missing(&db.orm).await.unwrap(); + assert_eq!(db.http_state("f").await.unwrap().body_hash.as_deref(), Some("def")); + } + #[tokio::test] async fn a_database_from_before_body_hashes_gains_the_columns() { let db = Db::memory().await.unwrap();