Skip to content

Commit

Permalink
implement eq_no_mtime for LibraryItem
Browse files Browse the repository at this point in the history
  • Loading branch information
unclekingpin committed Dec 1, 2023
1 parent db33fba commit 2681a36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ pub fn update_library<E: Env + 'static>(
.unchanged(),
},
Msg::Internal(Internal::UpdateLibraryItem(library_item))
if Some(library_item) != library.items.get(&library_item.id) =>
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 2681a36

Please sign in to comment.