From 0f5d610b4bc681ea9c956f5768ea1093620e9812 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Wed, 6 Oct 2021 21:21:03 +0200 Subject: [PATCH] Revert 10 track history window --- connect/src/spirc.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 2038c8bd..d644e2b0 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -84,6 +84,7 @@ struct SpircTaskConfig { autoplay: bool, } +const CONTEXT_TRACKS_HISTORY: usize = 10; const CONTEXT_FETCH_THRESHOLD: u32 = 5; const VOLUME_STEPS: i64 = 64; @@ -1051,9 +1052,21 @@ impl SpircTask { let new_tracks = &context.tracks; debug!("Adding {:?} tracks from context to frame", new_tracks.len()); let mut track_vec = self.state.take_track().into_vec(); + if let Some(head) = track_vec.len().checked_sub(CONTEXT_TRACKS_HISTORY) { + track_vec.drain(0..head); + } track_vec.extend_from_slice(new_tracks); self.state .set_track(protobuf::RepeatedField::from_vec(track_vec)); + + // Update playing index + if let Some(new_index) = self + .state + .get_playing_track_index() + .checked_sub(CONTEXT_TRACKS_HISTORY as u32) + { + self.state.set_playing_track_index(new_index); + } } else { warn!("No context to update from!"); }