forked from Furumi/furumi-web
Sync podcast state through the store instead of the relay
Received podcast operations and snapshot sections are applied to the podcast store, this device's snapshots are filled from it, and an unknown episode position resumes from its progress register. The relay module is removed; operations, gating and snapshot bounds on the wire are unchanged. The device-sync Postgres tests now migrate their database themselves and cover locally emitted podcast operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f07cb206a
commit
681ff7af89
4 files changed
+143
-609
No files matched your search
+41
-23
@@ -6,10 +6,10 @@
|
||||
//! `furumi/sync/2` and maps operations into user-scoped Postgres state.
|
||||
//!
|
||||
//! The wire types are the shared definitions; there are no local copies.
|
||||
//! Device-sync protocol v4 (podcasts) is announced because this adapter
|
||||
//! keeps every v4 element it receives: podcast operations stay in the
|
||||
//! generic operation log, podcast snapshot sections are merged into
|
||||
//! [`super::podcast_relay`], and queue items keep their explicit
|
||||
//! Device-sync protocol v4 (podcasts) is announced: podcast operations stay
|
||||
//! in the generic operation log and are applied to the account's podcast
|
||||
//! store ([`crate::podcasts::PodcastStore`]), which also provides the
|
||||
//! podcast snapshot sections, and queue items keep their explicit
|
||||
//! `PlaybackTrack.source` through the browser bridge
|
||||
//! ([`crate::player::queue_items`]). Everything sent to a peer is gated by
|
||||
//! the version that peer reported itself.
|
||||
@@ -39,8 +39,8 @@ use sqlx::Row;
|
||||
use crate::player::PlayerDeviceHub;
|
||||
use crate::player::queue_items;
|
||||
|
||||
use super::podcast_relay::{self, RelayRecord};
|
||||
use super::{TransportStats, record_stream_transport};
|
||||
use crate::podcasts::{ApplyOutcome, PodcastStore};
|
||||
|
||||
pub const SYNC_ALPN: &[u8] = b"furumi/sync/2";
|
||||
|
||||
@@ -2089,12 +2089,19 @@ async fn apply_op(
|
||||
| SyncOpPayload::PodcastFeedAliasesAdded { .. }
|
||||
| SyncOpPayload::PodcastProgressSet { .. }
|
||||
| SyncOpPayload::PodcastListenRecorded { .. } => {
|
||||
// The web player has no podcast features yet: keep the registers
|
||||
// for this device's snapshots; the operation itself is relayed
|
||||
// from the log.
|
||||
let records: Vec<_> = RelayRecord::from_op(op).into_iter().collect();
|
||||
podcast_relay::merge_records(pool, user_id, &records).await?;
|
||||
Ok(false)
|
||||
// The operation itself is relayed from the log; the store keeps
|
||||
// the registers (and the catalog rows of its episode reference).
|
||||
match PodcastStore::new(pool.clone())
|
||||
.apply_remote_op(user_id, op)
|
||||
.await?
|
||||
{
|
||||
ApplyOutcome::Changed => Ok(true),
|
||||
ApplyOutcome::Rejected(reason) => {
|
||||
tracing::debug!(op_id = %op.op_id, "skipped invalid podcast operation: {reason}");
|
||||
Ok(false)
|
||||
}
|
||||
ApplyOutcome::Unchanged | ApplyOutcome::Ignored => Ok(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2461,13 +2468,17 @@ async fn apply_playlist_item_state(
|
||||
}
|
||||
|
||||
async fn apply_snapshot(pool: &sqlx::PgPool, user_id: i64, snapshot: SyncSnapshot) -> Result<()> {
|
||||
let podcast = SyncSnapshot {
|
||||
podcast_subscriptions: snapshot.podcast_subscriptions.clone(),
|
||||
podcast_shares: snapshot.podcast_shares.clone(),
|
||||
podcast_progress: snapshot.podcast_progress.clone(),
|
||||
podcast_listen_sessions: snapshot.podcast_listen_sessions.clone(),
|
||||
..SyncSnapshot::default()
|
||||
};
|
||||
let podcasts = PodcastStore::new(pool.clone())
|
||||
.apply_snapshot(user_id, &snapshot)
|
||||
.await?;
|
||||
if podcasts.ignored_over_limits {
|
||||
tracing::debug!("ignored podcast snapshot sections above the contract limits");
|
||||
} else if podcasts.rejected > 0 {
|
||||
tracing::debug!(
|
||||
rejected = podcasts.rejected,
|
||||
"skipped invalid podcast snapshot records"
|
||||
);
|
||||
}
|
||||
for like in snapshot.likes {
|
||||
apply_like_state(
|
||||
pool,
|
||||
@@ -2544,7 +2555,6 @@ async fn apply_snapshot(pool: &sqlx::PgPool, user_id: i64, snapshot: SyncSnapsho
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
podcast_relay::merge_records(pool, user_id, &RelayRecord::from_snapshot(&podcast)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3712,7 +3722,7 @@ fn playback_clock() -> u64 {
|
||||
///
|
||||
/// When the browser does not know the position of its current item
|
||||
/// ([`queue_items::POSITION_UNKNOWN_KEY`]) and that item is a podcast
|
||||
/// episode, the position comes from the relayed progress register: handing
|
||||
/// episode, the position comes from its synced progress register: handing
|
||||
/// 0 to the next device would be written there as an explicit action and
|
||||
/// restart the episode everywhere.
|
||||
async fn playback_state_from_browser_json(
|
||||
@@ -3728,8 +3738,9 @@ async fn playback_state_from_browser_json(
|
||||
.get(wire.queue_pos)
|
||||
.and_then(PlaybackTrack::podcast_episode_ref)
|
||||
{
|
||||
let record =
|
||||
podcast_relay::progress_record(pool, user_id, episode.episode_id.as_str()).await?;
|
||||
let record = PodcastStore::new(pool.clone())
|
||||
.progress(user_id, &episode.episode_id)
|
||||
.await?;
|
||||
apply_resume_position(&mut wire, record.as_ref());
|
||||
}
|
||||
Ok(wire)
|
||||
@@ -4644,7 +4655,14 @@ async fn snapshot(pool: &sqlx::PgPool, user_id: i64) -> Result<SyncSnapshot> {
|
||||
removed_playlist_items,
|
||||
..SyncSnapshot::default()
|
||||
};
|
||||
podcast_relay::fill_snapshot(pool, user_id, &mut snapshot).await?;
|
||||
// Bounded again per message by `fit_podcast_snapshot`.
|
||||
PodcastStore::new(pool.clone())
|
||||
.fill_snapshot(
|
||||
user_id,
|
||||
&mut snapshot,
|
||||
music_dht::podcast::MAX_PODCAST_SNAPSHOT_BYTES,
|
||||
)
|
||||
.await?;
|
||||
Ok(snapshot)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user