Bound user-started feed and audio requests per account

Feed downloads and proxy streams have per-account and server-wide
limits, new subscriptions stop at 1000 per account, and scheduled
refreshes take accounts in turns.

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:38 +02:00
1 parent 2eb27cfe77
commit cfebe1898f
9 files changed
+330 -18

No files matched your search

+93 -2
View File
@@ -1179,7 +1179,7 @@ async fn postgres_podcast_fetch_state_is_local_only() {
// Scheduling: overdue first, future and unsubscribed podcasts skipped.
let due: Vec<PodcastId> = store
.podcasts_due_for_refresh(now, 10_000)
.podcasts_due_for_refresh(now, 10_000, usize::MAX)
.await
.unwrap()
.into_iter()
@@ -1606,10 +1606,101 @@ fn local_fetcher() -> FeedFetcher {
)
}
#[tokio::test]
#[ignore = "requires a disposable database in FURU_DEVICE_SYNC_TEST_DATABASE_URL"]
async fn postgres_podcast_refresh_takes_accounts_in_turns() {
let pool = test_pool().await;
let store = PodcastStore::new(pool.clone());
let (busy, quiet) = (random_user(), random_user());
let now = 1_900_000_000_000;
let mut busy_ids = Vec::new();
for (index, path) in ["turn-a.xml", "turn-b.xml", "turn-c.xml"]
.iter()
.enumerate()
{
let id = store
.subscribe(busy, &meta(path, "Busy"))
.await
.unwrap()
.podcast_id;
// The busy account's podcasts are the most overdue ones.
store
.record_fetch_failure(busy, &id, now, "x", Some(now - 10_000 + index as i64))
.await
.unwrap();
busy_ids.push(id);
}
let quiet_id = store
.subscribe(quiet, &meta("turn-q.xml", "Quiet"))
.await
.unwrap()
.podcast_id;
store
.record_fetch_failure(quiet, &quiet_id, now, "x", Some(now - 1))
.await
.unwrap();
let due = |per_account| {
let store = store.clone();
async move {
store
.podcasts_due_for_refresh(now, 100_000, per_account)
.await
.unwrap()
.into_iter()
.filter(|(user, ..)| [busy, quiet].contains(user))
.map(|(user, id, _)| (user, id))
.collect::<Vec<_>>()
}
};
assert_eq!(
due(2).await,
vec![
(busy, busy_ids[0].clone()),
(quiet, quiet_id.clone()),
(busy, busy_ids[1].clone()),
],
"one turn per account, at most two each"
);
assert_eq!(due(usize::MAX).await.len(), 4);
// New subscriptions stop at the per-account limit.
sqlx::query(
"INSERT INTO furumusic__podcast_subscription
(user_id, podcast_id, subscribed, podcast_json, generation, hlc_ms, op_id)
SELECT $1, 'pod1:cap' || n, TRUE, '{}'::jsonb, 1, 1, 'x:' || n
FROM generate_series(1, $2) AS n",
)
.bind(quiet)
.bind(i32::try_from(MAX_SUBSCRIPTIONS_PER_ACCOUNT - 1).unwrap())
.execute(&pool)
.await
.unwrap();
let error = store
.subscribe(quiet, &meta("turn-over.xml", "Over"))
.await
.unwrap_err();
assert_eq!(
error.downcast_ref::<PodcastStoreError>(),
Some(&PodcastStoreError::SubscriptionLimit(
MAX_SUBSCRIPTIONS_PER_ACCOUNT
))
);
// Subscribing again to a podcast already subscribed is not new.
assert!(
store
.subscribe(quiet, &meta("turn-q.xml", "Quiet"))
.await
.unwrap()
.already_subscribed
);
cleanup(&pool, [busy, quiet]).await;
}
/// Due groups of the given accounts only (other tests share the database).
async fn due_for(store: &PodcastStore, users: &[i64], now: i64) -> runner::RefreshGroups {
let due = store
.podcasts_due_for_refresh(now, 100_000)
.podcasts_due_for_refresh(now, 100_000, usize::MAX)
.await
.unwrap()
.into_iter()