From ba5fb1f8bf17e368d02475eec0fcf1916db7c335 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 9 Dec 2023 15:26:19 +0100 Subject: [PATCH] store genres when fetching import releases --- entity/src/genre_release.rs | 30 +++++++++++++++++++++++- entity/src/genre_track.rs | 30 +++++++++++++++++++++++- server/src/tasks/import/fetch_release.rs | 10 ++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/entity/src/genre_release.rs b/entity/src/genre_release.rs index 606f9aa..9ba08d4 100644 --- a/entity/src/genre_release.rs +++ b/entity/src/genre_release.rs @@ -2,7 +2,7 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, DeriveEntityModel)] +#[derive(Serialize, Deserialize, Clone, Debug, DeriveEntityModel)] #[sea_orm(table_name = "genre_release")] pub struct Model { #[sea_orm(primary_key)] @@ -40,3 +40,31 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +impl PartialEq for Model { + fn eq(&self, other: &Self) -> bool { + self.genre_id.eq(&other.genre_id) && self.release_id.eq(&other.release_id) + } +} +impl Eq for Model {} + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.genre_id.lt(&other.genre_id) && self.release_id.lt(&other.release_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + self.genre_id + .partial_cmp(&other.genre_id) + .and(self.release_id.partial_cmp(&other.release_id)) + } +} + +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + if self.eq(other) { + std::cmp::Ordering::Equal + } else { + self.genre_id.cmp(&other.genre_id) + } + } +} diff --git a/entity/src/genre_track.rs b/entity/src/genre_track.rs index 126749b..2415645 100644 --- a/entity/src/genre_track.rs +++ b/entity/src/genre_track.rs @@ -2,7 +2,7 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, DeriveEntityModel)] +#[derive(Serialize, Deserialize, Clone, Debug, DeriveEntityModel)] #[sea_orm(table_name = "genre_track")] pub struct Model { #[sea_orm(primary_key)] @@ -41,3 +41,31 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +impl PartialEq for Model { + fn eq(&self, other: &Self) -> bool { + self.genre_id.eq(&other.genre_id) && self.track_id.eq(&other.track_id) + } +} +impl Eq for Model {} + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.genre_id.lt(&other.genre_id) && self.track_id.lt(&other.track_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + self.genre_id + .partial_cmp(&other.genre_id) + .and(self.track_id.partial_cmp(&other.track_id)) + } +} + +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + if self.eq(other) { + std::cmp::Ordering::Equal + } else { + self.genre_id.cmp(&other.genre_id) + } + } +} diff --git a/server/src/tasks/import/fetch_release.rs b/server/src/tasks/import/fetch_release.rs index e34a055..bb77504 100644 --- a/server/src/tasks/import/fetch_release.rs +++ b/server/src/tasks/import/fetch_release.rs @@ -131,6 +131,16 @@ impl crate::tasks::TaskTrait for Data { dedup(import.artist_credit_tracks.0), )); + import.genres.0.extend(release.genres); + import_active.genres = ActiveValue::Set(entity::import::Genres(dedup(import.genres.0))); + import.track_genres.0.extend(release.track_genres); + import_active.track_genres = + ActiveValue::Set(entity::import::TrackGenres(dedup(import.track_genres.0))); + import.release_genres.0.extend(release.release_genres); + import_active.release_genres = ActiveValue::Set(entity::import::ReleaseGenres(dedup( + import.release_genres.0, + ))); + import_active.update(&tx).await?; tx.commit().await?;