Keep a rollback to 0.12 safe for sync and the typed queue
Release 0.12 fails a whole sync batch on a podcast operation kind, so rolling back is only safe after the relayed podcast operations are removed: document the step in docs/administration.md and run it in the m_0055 backwards operation. The typed queue now records the current track id and queue position written with it, next to the legacy ids. A 0.12 release that only moved to another track in the same queue no longer leaves a stale typed position that the next upgrade would restore. Jam placeholders are never stored in a user's own typed queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f3ed4b7ee
commit
3af0e8ccc9
6 files changed
+219
-48
No files matched your search
@@ -1438,12 +1438,14 @@ async fn delete_entities(
|
||||
}
|
||||
}
|
||||
// Playback queues contain local IDs rather than foreign keys.
|
||||
let states: Vec<(i64, Option<i64>, String, Option<serde_json::Value>)> = sqlx::query_as(
|
||||
"SELECT id,current_track_id,queue_json,queue_items_json FROM furumusic__playback_state FOR UPDATE",
|
||||
// (id, current_track_id, queue_json, queue_items_json, queue_position)
|
||||
type QueueRow = (i64, Option<i64>, String, Option<serde_json::Value>, i32);
|
||||
let states: Vec<QueueRow> = sqlx::query_as(
|
||||
"SELECT id,current_track_id,queue_json,queue_items_json,queue_position FROM furumusic__playback_state FOR UPDATE",
|
||||
)
|
||||
.fetch_all(&mut *conn)
|
||||
.await?;
|
||||
for (id, current, queue_json, queue_items_json) in states {
|
||||
for (id, current, queue_json, queue_items_json, queue_position) in states {
|
||||
let mut queue: Vec<i64> = serde_json::from_str(&queue_json).unwrap_or_default();
|
||||
if !current.is_some_and(|id| deleted.tracks.contains(&id))
|
||||
&& !queue.iter().any(|id| deleted.tracks.contains(id))
|
||||
@@ -1452,7 +1454,11 @@ async fn delete_entities(
|
||||
}
|
||||
let mut typed = crate::player::queue_items::StoredQueue::from_columns(
|
||||
queue_items_json.as_ref(),
|
||||
&queue,
|
||||
&crate::player::queue_items::LegacyColumns {
|
||||
queue: queue.clone(),
|
||||
current_track_id: current,
|
||||
queue_position,
|
||||
},
|
||||
);
|
||||
let before: String = sqlx::query_scalar(
|
||||
"SELECT to_jsonb(t)::text FROM furumusic__playback_state t WHERE id=$1",
|
||||
@@ -1461,14 +1467,21 @@ async fn delete_entities(
|
||||
.fetch_one(&mut *conn)
|
||||
.await?;
|
||||
queue.retain(|id| !deleted.tracks.contains(id));
|
||||
if let Some(typed) = &mut typed {
|
||||
typed.retain_library(|id| !deleted.tracks.contains(&id), queue.clone());
|
||||
}
|
||||
let queue_items_json = typed.map(serde_json::to_value).transpose()?;
|
||||
let current = current.filter(|id| !deleted.tracks.contains(id));
|
||||
let position = current
|
||||
.and_then(|id| queue.iter().position(|x| *x == id))
|
||||
.unwrap_or(0) as i32;
|
||||
if let Some(typed) = &mut typed {
|
||||
typed.retain_library(
|
||||
|id| !deleted.tracks.contains(&id),
|
||||
crate::player::queue_items::LegacyColumns {
|
||||
queue: queue.clone(),
|
||||
current_track_id: current,
|
||||
queue_position: position,
|
||||
},
|
||||
);
|
||||
}
|
||||
let queue_items_json = typed.map(serde_json::to_value).transpose()?;
|
||||
let after: String = sqlx::query_scalar("UPDATE furumusic__playback_state SET current_track_id=$2,queue_json=$3,queue_position=$4,queue_items_json=$5,position_ms=CASE WHEN current_track_id IS DISTINCT FROM $2 THEN 0 ELSE position_ms END WHERE id=$1 RETURNING to_jsonb(furumusic__playback_state)::text")
|
||||
.bind(id).bind(current).bind(serde_json::to_string(&queue)?).bind(position).bind(queue_items_json).fetch_one(&mut *conn).await?;
|
||||
archived.push(ArchivedRows {
|
||||
|
||||
Reference in new issue
Block a user