diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md index 643a9c4..301ba83 100644 --- a/crates/ipx/CHANGELOG.md +++ b/crates/ipx/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- A feed an OPML stops listing leaves All Subscriptions with it, rather than its items staying there with no feed name beside them: the scan no longer reads it again after the list drops it, and its subscriptions go with it (#478). +- A feed an OPML stops listing leaves All Subscriptions with it, rather than its items staying there with no feed name beside them: the scan no longer reads it again after the list drops it, and its subscriptions go with it, as they do when a feed is removed with `ipx rm`. Any left from before are removed when ipx starts (#478). - Searching All Subscriptions answers in a fraction of a second, not five: a search reads each item's title and text without its markup, indexed on Postgres, and still finds part of a word. It no longer matches words inside the HTML's tags, such as a link's address. Text past the first 4,000 characters of a very long post is not searched (#459, #472). - Artwork that cannot be shown is asked for again a day later rather than every hour: one too large is refused on its stated size before it is read, and a refusal from the publisher or one ipx makes (too large, not an image) is remembered for a day; JPEG XL pictures sent without a type are shown (#448). - `ipx reap --dry-run` says "would delete" of each file and of the total, rather than "deleted", word for word a real reap, of files it kept (#461). diff --git a/crates/ipx/src/catalogue.rs b/crates/ipx/src/catalogue.rs index c175a53..1d38af6 100644 --- a/crates/ipx/src/catalogue.rs +++ b/crates/ipx/src/catalogue.rs @@ -481,6 +481,27 @@ pub(crate) async fn retire_stranded(ctx: &Ctx) -> Result { Ok(before.len() - ctx.db.managed_feeds().await?.len()) } +/// Unsubscribes everyone from feeds the catalogue no longer has, and returns how many feeds that +/// was. Removing a feed once left its subscriptions behind, 41 of them by 2026-11-19, and All +/// Subscriptions listed their items with no feed to name them (#478). +pub(crate) async fn drop_stray_subscriptions(ctx: &Ctx) -> Result { + let known: std::collections::HashSet = subscriptions(ctx).await?.into_iter().map(|s| s.id).collect(); + // A catalogue that came back empty is more likely a fault than a server with no feeds, and + // taking it at its word would unsubscribe everyone from everything. + if known.is_empty() { + return Ok(0); + } + let mut dropped = 0; + for feed in ctx.db.subscriber_counts().await?.into_keys().filter(|f| !known.contains(f)) { + for (user, _) in ctx.db.subscribers_of(&feed).await? { + ctx.db.unsubscribe(user, &feed).await?; + } + tracing::info!(feed = %feed, "unsubscribed everyone from a feed no longer in the catalogue"); + dropped += 1; + } + Ok(dropped) +} + /// Puts each feed no longer derived in the group its catalogue entry says, and returns how many /// moved. Made a feed of its own before #358, a show kept its list's group in the database, and /// hiding the list from All Subscriptions hid it too. @@ -716,6 +737,21 @@ mod tests { assert_eq!(regroup_unmanaged(&ctx).await.unwrap(), 0, "nothing left to move"); } + #[tokio::test] + async fn a_subscription_to_a_feed_not_in_the_catalogue_is_dropped() { + let mut cfg = config::Config::default(); + cfg.feeds.insert("opml".into(), feed()); + let ctx = test_ctx(cfg).await; + let me = ctx.db.create_user("me", None, false).await.unwrap(); + ctx.db.upsert_managed("listed", "http://x/l.xml", "Listed", "opml").await.unwrap(); + for id in ["opml", "listed", "gone"] { + ctx.db.subscribe(me, id).await.unwrap(); + } + assert_eq!(drop_stray_subscriptions(&ctx).await.unwrap(), 1); + let mine: Vec = ctx.db.subscriptions_for(me).await.unwrap().into_iter().map(|s| s.feed_id).collect(); + assert!(mine.contains(&"opml".into()) && mine.contains(&"listed".into()) && !mine.contains(&"gone".into())); + } + #[tokio::test] async fn a_stranded_group_is_retired_but_a_promoted_feed_keeps_its_entries() { // davewiner: the OPML left config before retire_group existed, and 11 of its feeds diff --git a/crates/ipx/src/daemon.rs b/crates/ipx/src/daemon.rs index 1ac84f4..6c2db7e 100644 --- a/crates/ipx/src/daemon.rs +++ b/crates/ipx/src/daemon.rs @@ -97,6 +97,12 @@ pub(crate) async fn daemon( Ok(n) => tracing::info!(feeds = n, "retired feeds whose OPML is no longer in config"), Err(e) => tracing::warn!(error = %format!("{e:#}"), "could not retire feeds whose OPML is no longer in config"), } + // After retire_stranded, which drops feeds whose subscriptions this then finds. + match catalogue::drop_stray_subscriptions(&ctx).instrument(db::step("drop_stray_subscriptions")).await { + Ok(0) => {} + Ok(n) => tracing::info!(feeds = n, "unsubscribed everyone from feeds no longer in the catalogue"), + Err(e) => tracing::warn!(error = %format!("{e:#}"), "could not drop subscriptions to feeds no longer in the catalogue"), + } match catalogue::regroup_unmanaged(&ctx).instrument(db::step("regroup_unmanaged")).await { Ok(0) => {} Ok(n) => tracing::info!(feeds = n, "took feeds of their own out of their old list's group"),