Skip to content
Snippets Groups Projects
Verified Commit f0a827e4 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fix preview grouping

parent 94b2b86e
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ pub fn load_title(db: &PgConnection, config: &Config, title: Title) -> QueryResu
title, title_names, title_descriptions,
title_cast, title_genres, title_ratings,
title_images, title_media, title_subtitles,
title_preview,
Some(title_preview),
))
}
......@@ -63,8 +63,12 @@ pub fn load_titles(db: &PgConnection, config: &Config, titles: Vec<Title>) -> Qu
let title_subtitles: Vec<Vec<TitleSubtitle>> = TitleSubtitle::belonging_to(&titles)
.load::<TitleSubtitle>(db)?
.grouped_by(&titles);
let title_preview: Vec<TitlePreview> = TitlePreview::belonging_to(&titles)
.load::<TitlePreview>(db)?;
let title_preview: Vec<Option<TitlePreview>> = TitlePreview::belonging_to(&titles)
.load::<TitlePreview>(db)?
.grouped_by(&titles)
.into_iter()
.map(|vec: Vec<TitlePreview>| vec.into_iter().next())
.collect::<Vec<_>>();
Ok(titles.into_iter()
.zip(title_names)
.zip(title_descriptions)
......@@ -94,7 +98,7 @@ fn process_title(
title: Title, names: Vec<TitleName>, descriptions: Vec<TitleDescription>,
cast: Vec<(TitleCast, Person)>, genres: Vec<(TitleGenre, Genre)>, ratings: Vec<TitleRating>,
images: Vec<TitleImage>, media: Vec<TitleMedium>, subtitles: Vec<TitleSubtitle>,
preview: TitlePreview,
preview: Option<TitlePreview>,
) -> TitleDto {
TitleDto::of(
title,
......@@ -123,7 +127,9 @@ fn process_title(
subtitles.into_iter().filter_map(|src| {
SubtitleDto::of(src, &config).ok()
}).collect::<Vec<_>>(),
preview.src.and_then(|preview| absolute_url(config, preview).ok())
preview
.and_then(|preview| preview.src)
.and_then(|preview| absolute_url(config, preview).ok())
)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment