diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md index 8914139..643a9c4 100644 --- a/crates/ipx/CHANGELOG.md +++ b/crates/ipx/CHANGELOG.md @@ -35,6 +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). - 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/db.rs b/crates/ipx/src/db.rs index 0408b04..cea64a7 100644 --- a/crates/ipx/src/db.rs +++ b/crates/ipx/src/db.rs @@ -2708,6 +2708,8 @@ impl Db { self.exec("DELETE FROM feeds WHERE id = $1 AND managed", vec![id.into()]).await?; self.exec("DELETE FROM entries WHERE feed_id = $1", vec![id.into()]).await?; self.exec("DELETE FROM enclosures WHERE feed_id = $1 AND path IS NULL", vec![id.into()]).await?; + // Left behind, All Subscriptions listed the items of a feed no list had a name for (#478). + self.exec("DELETE FROM subscriptions WHERE feed_id = $1", vec![id.into()]).await?; Ok(()) } diff --git a/crates/ipx/src/lists.rs b/crates/ipx/src/lists.rs index 13c6ead..b42cdf8 100644 --- a/crates/ipx/src/lists.rs +++ b/crates/ipx/src/lists.rs @@ -182,7 +182,7 @@ pub(crate) async fn sync_group(ctx: &Arc, parent_id: &str, listed: &[(Strin .await?; // Anything in this group the OPML no longer lists. - let mut removed = 0; + let mut removed = vec![]; let mut kept = 0; let parent = ctx.cfg().feeds.get(parent_id).cloned(); async { @@ -203,7 +203,7 @@ pub(crate) async fn sync_group(ctx: &Arc, parent_id: &str, listed: &[(Strin tracing::info!(feed = %m.id, "dropped from the OPML but has downloads; keeping it"); } else { ctx.db.drop_managed(&m.id).await?; - removed += 1; + removed.push(m.id.clone()); tracing::info!(feed = %m.id, "dropped from the OPML with nothing downloaded; removed"); } } @@ -291,4 +291,21 @@ mod tests { assert!(ctx.db.subscription(me, "b").await.unwrap().is_some()); assert!(ctx.db.subscription(you, "b").await.unwrap().is_none()); } + + #[tokio::test] + async fn a_feed_the_list_drops_takes_its_subscriptions_with_it() { + let mut cfg = config::Config::default(); + cfg.feeds.insert("opml".into(), feed()); + let ctx = Arc::new(test_ctx(cfg).await); + let me = ctx.db.create_user("me", None, false).await.unwrap(); + ctx.db.upsert_managed("a", "http://x/a.xml", "a", "opml").await.unwrap(); + ctx.db.subscribe(me, "opml").await.unwrap(); + ctx.db.subscribe(me, "a").await.unwrap(); + + // Left subscribed, All Subscriptions listed a's items with no feed to name them (#478). + let Outcome::Opml { removed, .. } = sync_group(&ctx, "opml", &[]).await.unwrap() else { panic!("a list") }; + assert_eq!(removed, ["a"], "the scan is told, so it does not read a again"); + assert!(ctx.db.subscription(me, "a").await.unwrap().is_none()); + assert!(ctx.db.subscription(me, "opml").await.unwrap().is_some()); + } } diff --git a/crates/ipx/src/scan.rs b/crates/ipx/src/scan.rs index 92b6fb4..73eb244 100644 --- a/crates/ipx/src/scan.rs +++ b/crates/ipx/src/scan.rs @@ -5,6 +5,7 @@ use crate::ctx::Ctx; use crate::ipc::Event; use crate::{catalogue, cli, config, db, download, feed, lists, metrics, signals, torrent}; use anyhow::Result; +use std::collections::HashSet; use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -23,6 +24,8 @@ pub(crate) async fn fetch(ctx: &Arc, only: Option<&str>, force: bool, scope let subscribed = ctx.db.subscriber_counts().await?; let mut scanned = 0; let mut fresh: Vec = vec![]; + // Feeds a list read earlier in this run dropped: still in `due`, scanned they came back (#478). + let mut dropped: HashSet = HashSet::new(); let in_scope = |s: &Sub| scope.is_empty() || scope.contains(&s.id) || s.cfg.group.as_ref().is_some_and(|g| scope.contains(g)); let mut states = ctx.db.http_states().await?; @@ -95,6 +98,9 @@ pub(crate) async fn fetch(ctx: &Arc, only: Option<&str>, force: bool, scope let (id, feed_cfg) = (&sub.id, &sub.cfg); // A task that panicked has no body; scan_one then fetches it itself. let fetched = futures_util::StreamExt::next(&mut bodies).await.and_then(|j| j.ok()).flatten(); + if dropped.contains(id) { + continue; + } scanned += 1; ctx.out.emit(Event::FeedStart { feed: id.clone() }); match scan_one(ctx, id, feed_cfg, state, force, fetched).await { @@ -113,10 +119,12 @@ pub(crate) async fn fetch(ctx: &Arc, only: Option<&str>, force: bool, scope ctx.out.emit(Event::FeedSkip { feed: id.clone(), reason: format!( - "{total} feed(s) listed, {} added, {removed} unsubscribed, {kept} kept without a listing", - added.len() + "{total} feed(s) listed, {} added, {} unsubscribed, {kept} kept without a listing", + added.len(), + removed.len() ), }); + dropped.extend(removed); // Read them in the same pass, as the original did, rather than making // the user wait a whole interval for a newly listed show. fresh.extend(added); @@ -247,7 +255,7 @@ pub(crate) enum Outcome { /// The URL is a list of feeds rather than a feed: an OPML, or a Patreon creator's shows. Opml { added: Vec, - removed: usize, + removed: Vec, kept: usize, total: usize, },