diff --git a/src/models/player.rs b/src/models/player.rs index e502511f8..c8601cdb4 100644 --- a/src/models/player.rs +++ b/src/models/player.rs @@ -32,12 +32,10 @@ use derivative::Derivative; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - /// The duration that must have passed in order for a library item to be updated. - pub static ref PUSH_TO_LIBRARY_EVERY: Duration = Duration::seconds(30); -} +/// The duration that must have passed in order for a library item to be updated. +pub static PUSH_TO_LIBRARY_EVERY: Lazy = Lazy::new(|| Duration::seconds(90)); #[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -438,16 +436,7 @@ impl UpdateWithCtx for Player { }; let push_to_library_effects = - if E::now() - self.push_library_item_time >= *PUSH_TO_LIBRARY_EVERY { - self.push_library_item_time = E::now(); - - Effects::msg(Msg::Internal(Internal::UpdateLibraryItem( - library_item.to_owned(), - ))) - .unchanged() - } else { - Effects::none().unchanged() - }; + push_to_library::(&mut self.push_library_item_time, library_item); trakt_event_effects.join(push_to_library_effects) } @@ -630,6 +619,24 @@ impl UpdateWithCtx for Player { } } +/// We will push an [`Internal::UpdateLibraryItem`] message only if +/// at least [`PUSH_TO_LIBRARY_EVERY`] time has passed since the last update. +fn push_to_library( + push_library_item_time: &mut DateTime, + library_item: &mut LibraryItem, +) -> Effects { + if E::now() - *push_library_item_time >= *PUSH_TO_LIBRARY_EVERY { + *push_library_item_time = E::now(); + + Effects::msg(Msg::Internal(Internal::UpdateLibraryItem( + library_item.to_owned(), + ))) + .unchanged() + } else { + Effects::none().unchanged() + } +} + fn switch_to_next_video( library_item: &mut Option, next_video: &Option