Skip to content

Commit

Permalink
Merge pull request #571 from Stremio/lib-update-optimization
Browse files Browse the repository at this point in the history
prevent unnecessary library updates
  • Loading branch information
unclekingpin authored Dec 1, 2023
2 parents f2517fb + 2681a36 commit 316c74e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ pub fn update_library<E: Env + 'static>(
}))
.unchanged(),
},
Msg::Internal(Internal::UpdateLibraryItem(library_item)) => {
Msg::Internal(Internal::UpdateLibraryItem(library_item))
if library
.items
.get(&library_item.id)
.map(|prev_library_item| !library_item.eq_no_mtime(prev_library_item))
.unwrap_or(true) =>
{
let mut library_item = library_item.to_owned();
library_item.mtime = E::now();

Expand Down
14 changes: 14 additions & 0 deletions src/types/library/library_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ impl LibraryItem {
&& !self.removed
&& !self.temp
}

#[inline]
pub fn eq_no_mtime(&self, other: &LibraryItem) -> bool {
self.id == other.id
&& self.removed == other.removed
&& self.temp == other.temp
&& self.ctime == other.ctime
&& self.state == other.state
&& self.name == other.name
&& self.r#type == other.r#type
&& self.poster == other.poster
&& self.poster_shape == other.poster_shape
&& self.behavior_hints == other.behavior_hints
}
}

impl<E: Env + 'static> From<(&MetaItemPreview, PhantomData<E>)> for LibraryItem {
Expand Down

0 comments on commit 316c74e

Please sign in to comment.