Subscriptions to a feed no longer in the catalogue are dropped at start (#478)

The ways a feed leaves the catalogue now take its subscriptions with
it, but any path missed now or added later would leave the same
leftover: items in All Subscriptions with no feed to name them. Each
start now unsubscribes everyone from a feed the catalogue does not
have, after retire_stranded, unless the catalogue is empty, which is
likelier a fault than a server with no feeds.

The 41 already in production (all from the Hacker News top feeds OPML,
which drops feeds daily) were deleted by hand on 2026-11-19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVAJFkEgz9cXG3jG1Zy
This commit is contained in:
2026-11-19 07:39:00 -05:00
parent 349426cbf9
commit 4120bcd369
3 changed files with 43 additions and 1 deletions

View File

@@ -32,7 +32,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).

View File

@@ -481,6 +481,27 @@ pub(crate) async fn retire_stranded(ctx: &Ctx) -> Result<usize> {
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<usize> {
let known: std::collections::HashSet<String> = 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<String> = 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

View File

@@ -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"),