Skip to content

Commit

Permalink
store genres when fetching import releases
Browse files Browse the repository at this point in the history
  • Loading branch information
lucat1 committed Dec 9, 2023
1 parent e8d14ab commit ba5fb1f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
30 changes: 29 additions & 1 deletion entity/src/genre_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -40,3 +40,31 @@ impl Related<super::release::Entity> 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<std::cmp::Ordering> {
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)
}
}
}
30 changes: 29 additions & 1 deletion entity/src/genre_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -41,3 +41,31 @@ impl Related<super::track::Entity> 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<std::cmp::Ordering> {
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)
}
}
}
10 changes: 10 additions & 0 deletions server/src/tasks/import/fetch_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down

0 comments on commit ba5fb1f

Please sign in to comment.