Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backporting the ratelimit from ryot-pro #1006

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions crates/providers/src/anilist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,35 +541,36 @@ async fn media_details(
.map_err(|e| anyhow!(e))?
.json::<Response<media_details_query::ResponseData>>()
.await
.map_err(|e| anyhow!(e))?
.data
.unwrap()
.media
.unwrap();
let mut images = Vec::from_iter(details.cover_image.and_then(|i| i.extra_large));
if let Some(i) = details.banner_image {
.map_err(|e| anyhow!(e))?;

// Handles rate limit timeout
let data = details.data.ok_or_else(|| anyhow!("No data in response"))?;
let media = data.media.ok_or_else(|| anyhow!("No media in data"))?;

let mut images = Vec::from_iter(media.cover_image.and_then(|i| i.extra_large));
if let Some(i) = media.banner_image {
images.push(i);
}
let images = images
let images = media
.into_iter()
.map(|i| MetadataImageForMediaDetails { image: i })
.unique()
.collect();
let mut genres = details
let mut genres = media
.genres
.into_iter()
.flatten()
.map(|t| t.unwrap())
.collect_vec();
genres.extend(
details
media
.tags
.unwrap_or_default()
.into_iter()
.flatten()
.map(|t| t.name),
);
let mut people = Vec::from_iter(details.staff)
let mut people = Vec::from_iter(media.staff)
.into_iter()
.flat_map(|s| s.edges.unwrap())
.flatten()
Expand All @@ -586,7 +587,7 @@ async fn media_details(
})
.collect_vec();
people.extend(
Vec::from_iter(details.studios)
Vec::from_iter(media.studios)
.into_iter()
.flat_map(|s| s.edges.unwrap())
.flatten()
Expand All @@ -606,7 +607,7 @@ async fn media_details(
}),
);
let people = people.into_iter().unique().collect_vec();
let airing_schedule = details.airing_schedule.and_then(|a| a.nodes).map(|a| {
let airing_schedule = media.airing_schedule.and_then(|a| a.nodes).map(|a| {
a.into_iter()
.flat_map(|s| {
s.and_then(|data| {
Expand All @@ -620,11 +621,11 @@ async fn media_details(
})
.collect_vec()
});
let (lot, anime_specifics, manga_specifics) = match details.type_.unwrap() {
let (lot, anime_specifics, manga_specifics) = match media.type_.unwrap() {
media_details_query::MediaType::ANIME => (
MediaLot::Anime,
Some(AnimeSpecifics {
episodes: details.episodes.and_then(|c| c.try_into().ok()),
episodes: media.episodes.and_then(|c| c.try_into().ok()),
airing_schedule,
}),
None,
Expand All @@ -633,19 +634,19 @@ async fn media_details(
MediaLot::Manga,
None,
Some(MangaSpecifics {
chapters: details.chapters.and_then(|c| c.try_into().ok()),
volumes: details.volumes.and_then(|v| v.try_into().ok()),
chapters: media.chapters.and_then(|c| c.try_into().ok()),
volumes: media.volumes.and_then(|v| v.try_into().ok()),
url: None,
}),
),
media_details_query::MediaType::Other(_) => unreachable!(),
};

let year = details
let year = media
.start_date
.and_then(|b| b.year.map(|y| y.try_into().unwrap()));

let suggestions = details
let suggestions = media
.recommendations
.unwrap()
.nodes
Expand Down Expand Up @@ -674,16 +675,16 @@ async fn media_details(
})
})
.collect();
let score = details.average_score.map(Decimal::from);
let videos = Vec::from_iter(details.trailer.map(|t| MetadataVideo {
let score = media.average_score.map(Decimal::from);
let videos = Vec::from_iter(media.trailer.map(|t| MetadataVideo {
identifier: StoredUrl::Url(t.id.unwrap()),
source: match t.site.unwrap().as_str() {
"youtube" => MetadataVideoSource::Youtube,
"dailymotion" => MetadataVideoSource::Dailymotion,
_ => unreachable!(),
},
}));
let title = details.title.unwrap();
let title = media.title.unwrap();
let title = get_in_preferred_language(
title.native,
title.english,
Expand All @@ -692,10 +693,10 @@ async fn media_details(
);
Ok(MediaDetails {
title,
identifier: details.id.to_string(),
is_nsfw: details.is_adult,
identifier: media.id.to_string(),
is_nsfw: media.is_adult,
source: MediaSource::Anilist,
description: details.description,
description: media.description,
lot,
people,
creators: vec![],
Expand All @@ -710,7 +711,7 @@ async fn media_details(
provider_rating: score,
group_identifiers: vec![],
s3_images: vec![],
production_status: media_status_string(details.status),
production_status: media_status_string(media.status),
original_language: None,
..Default::default()
})
Expand Down
35 changes: 19 additions & 16 deletions crates/services/miscellaneous/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3041,28 +3041,31 @@ impl MiscellaneousService {
}
}
for col_update in collection_updates.into_iter() {
let metadata::Model { id, .. } = self
IgnisDa marked this conversation as resolved.
Show resolved Hide resolved
let metadata_result = self
.commit_metadata(CommitMediaInput {
lot: col_update.lot,
source: col_update.source,
identifier: col_update.identifier.clone(),
force_update: None,
})
.await?;
add_entity_to_collection(
&self.db,
user_id,
ChangeCollectionToEntityInput {
creator_user_id: user_id.to_owned(),
collection_name: col_update.collection,
entity_id: id.clone(),
entity_lot: EntityLot::Metadata,
..Default::default()
},
&self.perform_core_application_job,
)
.await
.trace_ok();
.await;

if let Ok(metadata::Model { id, .. }) = metadata_result {
add_entity_to_collection(
&self.db,
user_id,
ChangeCollectionToEntityInput {
creator_user_id: user_id.to_owned(),
collection_name: col_update.collection,
entity_id: id.clone(),
entity_lot: EntityLot::Metadata,
..Default::default()
},
&self.perform_core_application_job,
)
.await
.trace_ok();
}
}
Integration::update_many()
.filter(integration::Column::Id.is_in(to_update_integrations))
Expand Down