Skip to content

Commit 1331ec3

Browse files
authored
Issue 879 (#880)
* refactor(backend): extract season name into constant * feat(backend): do not create calendar events for specials * feat(database): delete all invalid calendar events
1 parent 131a90f commit 1331ec3

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

apps/backend/src/miscellaneous/resolver.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ use crate::{
119119
utils::{
120120
add_entity_to_collection, associate_user_with_entity, entity_in_collections,
121121
get_current_date, get_stored_asset, get_user_to_entity_association, ilike_sql,
122-
partial_user_by_id, user_by_id, user_id_from_token, AUTHOR, TEMP_DIR,
122+
partial_user_by_id, user_by_id, user_id_from_token, AUTHOR, SHOW_SPECIALS_SEASON_NAME,
123+
TEMP_DIR,
123124
},
124125
};
125126

@@ -5832,7 +5833,7 @@ impl MiscellaneousService {
58325833
let all_episodes = if let Some(s) = metadata.model.show_specifics {
58335834
s.seasons
58345835
.into_iter()
5835-
.filter(|s| s.name != "Specials")
5836+
.filter(|s| s.name != SHOW_SPECIALS_SEASON_NAME)
58365837
.flat_map(|s| {
58375838
s.episodes
58385839
.into_iter()
@@ -6686,6 +6687,9 @@ impl MiscellaneousService {
66866687
}
66876688
} else if let Some(ss) = &meta.show_specifics {
66886689
for season in ss.seasons.iter() {
6690+
if season.name == SHOW_SPECIALS_SEASON_NAME {
6691+
continue;
6692+
}
66896693
for episode in season.episodes.iter() {
66906694
if let Some(date) = episode.publish_date {
66916695
let event = calendar_event::ActiveModel {

apps/backend/src/providers/tmdb.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
IdObject, NamedObject, SearchDetails, SearchResults, StoredUrl,
3636
},
3737
traits::{MediaProvider, MediaProviderLanguages},
38-
utils::{get_base_http_client, get_current_date, TEMP_DIR},
38+
utils::{get_base_http_client, get_current_date, SHOW_SPECIALS_SEASON_NAME, TEMP_DIR},
3939
};
4040

4141
static URL: &str = "https://api.themoviedb.org/3/";
@@ -1119,7 +1119,7 @@ impl MediaProvider for TmdbShowService {
11191119
.sum();
11201120
let seasons_without_specials = seasons
11211121
.iter()
1122-
.filter(|s| s.name != "Specials")
1122+
.filter(|s| s.name != SHOW_SPECIALS_SEASON_NAME)
11231123
.collect_vec();
11241124
let total_seasons = seasons_without_specials.len();
11251125
let total_episodes = seasons_without_specials

apps/backend/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub const USER_AGENT_STR: &str = const_str::concat!(
6363
pub const AVATAR_URL: &str =
6464
"https://raw.githubusercontent.com/IgnisDa/ryot/main/libs/assets/icon-512x512.png";
6565
pub const TEMP_DIR: &str = "tmp";
66+
pub const SHOW_SPECIALS_SEASON_NAME: &str = "Specials";
6667
pub static JSON: HeaderValue = HeaderValue::from_static("application/json");
6768

6869
const FRONTEND_OAUTH_ENDPOINT: &str = "/api/auth";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
let db = manager.get_connection();
10+
db.execute_unprepared(
11+
r#"
12+
DELETE FROM "calendar_event" WHERE
13+
"metadata_show_extra_information" ->> 'season' = '0';
14+
"#,
15+
)
16+
.await?;
17+
18+
Ok(())
19+
}
20+
21+
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
22+
Ok(())
23+
}
24+
}

libs/database/src/migrations/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod m20240607_change_user_primary_key;
2525
mod m20240607_create_integration;
2626
mod m20240608_add_created_on_column_to_collection_to_entity;
2727
mod m20240619_remove_seen_from_media_reason_of_user_to_entity;
28+
mod m20240620_delete_invalid_calendar_events;
2829

2930
pub use m20230410_create_metadata::Metadata as AliasedMetadata;
3031
pub use m20230413_create_person::Person as AliasedPerson;
@@ -71,6 +72,7 @@ impl MigratorTrait for Migrator {
7172
Box::new(m20240607_create_integration::Migration),
7273
Box::new(m20240608_add_created_on_column_to_collection_to_entity::Migration),
7374
Box::new(m20240619_remove_seen_from_media_reason_of_user_to_entity::Migration),
75+
Box::new(m20240620_delete_invalid_calendar_events::Migration),
7476
]
7577
}
7678
}

0 commit comments

Comments
 (0)