Prefer the account's current subscription for a moved feed

An old, unsubscribed podcast of the same feed no longer hides the
podcast the account follows now: the preview marks the card as already
subscribed, and subscribing from the card or by URL no longer
resubscribes the old podcast next to the current one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:52 +02:00
1 parent c5f3b3cfa4
commit abd100d6e7
3 files changed
+94 -11

No files matched your search

+19 -9
View File
@@ -113,25 +113,35 @@ pub(crate) fn ranked_hits(
/// the podcast one of `feed_urls` resolves to through the account's known
/// feed URLs and aliases (the card's origin URL; after a fetch also where
/// the feed moved, see `runner::document_urls`).
///
/// A podcast the account is subscribed to comes first, so an old,
/// unsubscribed podcast of the same feed (followed once under its former
/// address) never hides the current subscription; otherwise the first
/// known one, in the order id, then `feed_urls`.
pub(crate) async fn known_podcast(
store: &PodcastStore,
user_id: i64,
podcast_id: &PodcastId,
feed_urls: &[FeedUrl],
) -> Result<Option<PodcastSummary>> {
if let Some(summary) = store.podcast(user_id, podcast_id).await? {
return Ok(Some(summary));
}
let mut ids = vec![podcast_id.clone()];
for feed_url in feed_urls {
let resolved = store.resolve_podcast_id(user_id, feed_url).await?;
if resolved == *podcast_id {
continue;
}
if let Some(summary) = store.podcast(user_id, &resolved).await? {
return Ok(Some(summary));
if !ids.contains(&resolved) {
ids.push(resolved);
}
}
Ok(None)
let mut first = None;
for id in ids {
let Some(summary) = store.podcast(user_id, &id).await? else {
continue;
};
if summary.subscribed {
return Ok(Some(summary));
}
first.get_or_insert(summary);
}
Ok(first)
}
/// Views of the podcast hits of one search for `user_id`, in rank order.
+72
View File
@@ -724,3 +724,75 @@ async fn postgres_a_feed_claiming_a_followed_address_never_rewrites_that_podcast
cleanup(&pool, [user]).await;
}
#[tokio::test]
#[ignore = "requires a disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
async fn postgres_a_current_subscription_wins_over_an_old_unsubscribed_podcast() {
let pool = test_pool().await;
let store = PodcastStore::new(pool.clone());
let user = random_user();
cleanup(&pool, [user]).await;
let server = TestServer::start();
server.set(
"/old.xml",
Route::new(rss("Moving Show", ITEMS), "application/rss+xml"),
);
server.set(
"/new.xml",
Route::new(rss("Moving Show", ITEMS), "application/rss+xml"),
);
let fetcher = local_fetcher();
let now = super::now_ms();
let old = hit(&server.url("/old.xml"), "Moving Show");
let new_id = PodcastId::from_feed_url(&url(&server.url("/new.xml")));
// Followed once under the old address, then unsubscribed; the feed
// moved, and the account follows it under the new address only.
runner::subscribe_url(&store, &fetcher, user, &old.feed_url, now)
.await
.unwrap();
store.unsubscribe(user, &old.podcast_id).await.unwrap();
server.set("/old.xml", Route::redirect(301, "/new.xml"));
let current = runner::subscribe_url(&store, &fetcher, user, &url(&server.url("/new.xml")), now)
.await
.unwrap();
assert_eq!(current.podcast_id, new_id);
assert!(!current.already_subscribed);
let known = super::search::known_podcast(
&store,
user,
&old.podcast_id,
&[old.feed_url.clone(), url(&server.url("/new.xml"))],
)
.await
.unwrap()
.unwrap();
assert_eq!(known.podcast_id, new_id);
assert!(known.subscribed);
let body =
json!({ "podcast_id": old.podcast_id.to_string(), "feed_url": old.feed_url.to_string() });
let preview = api::preview_found(&store, &fetcher, user, body.clone())
.await
.unwrap();
assert!(preview.subscribed);
assert_eq!(preview.local_podcast_id.as_deref(), Some(new_id.as_str()));
let log = log_len(&pool, user).await;
let found = api::subscribe_found(&store, &fetcher, user, body, now)
.await
.unwrap();
assert!(found.already_subscribed);
assert_eq!(found.podcast.podcast_id, new_id.to_string());
let added = runner::subscribe_url(&store, &fetcher, user, &old.feed_url, now)
.await
.unwrap();
assert!(added.already_subscribed);
assert_eq!(added.podcast_id, new_id);
assert_eq!(log_len(&pool, user).await, log);
assert_eq!(active_subscriptions(&pool, user).await, 1);
let old_podcast = store.podcast(user, &old.podcast_id).await.unwrap().unwrap();
assert!(!old_podcast.subscribed);
cleanup(&pool, [user]).await;
}