mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Disables many to many eager includes
This commit is contained in:
parent
48f82a6f13
commit
eed058c891
@ -1,29 +0,0 @@
|
||||
// Kyoo - A portable and vast media library solution.
|
||||
// Copyright (c) Kyoo.
|
||||
//
|
||||
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||
//
|
||||
// Kyoo is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// Kyoo is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
|
||||
namespace Kyoo.Abstractions.Models.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// The targeted relation can be edited via calls to the repository's <see cref="IRepository{T}.Edit"/> method.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class EditableRelationAttribute : Attribute { }
|
||||
}
|
@ -64,12 +64,12 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The list of movies contained in this collection.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Movie>? Movies { get; set; }
|
||||
[SerializeIgnore] public ICollection<Movie>? Movies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of shows contained in this collection.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Show>? Shows { get; set; }
|
||||
[SerializeIgnore] public ICollection<Show>? Shows { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
||||
|
@ -123,17 +123,17 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The Studio that made this show.
|
||||
/// </summary>
|
||||
[LoadableRelation(nameof(StudioId))][EditableRelation] public Studio? Studio { get; set; }
|
||||
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of people that made this show.
|
||||
/// </summary>
|
||||
[LoadableRelation][EditableRelation] public ICollection<PeopleRole>? People { get; set; }
|
||||
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of collections that contains this show.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Collection>? Collections { get; set; }
|
||||
[SerializeIgnore] public ICollection<Collection>? Collections { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Links to watch this movie.
|
||||
|
@ -61,7 +61,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The list of roles this person has played in. See <see cref="PeopleRole"/> for more information.
|
||||
/// </summary>
|
||||
[EditableRelation][LoadableRelation] public ICollection<PeopleRole>? Roles { get; set; }
|
||||
[SerializeIgnore] public ICollection<PeopleRole>? Roles { get; set; }
|
||||
|
||||
public People() { }
|
||||
|
||||
|
@ -121,7 +121,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The list of episodes that this season contains.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Episode>? Episodes { get; set; }
|
||||
[SerializeIgnore] public ICollection<Episode>? Episodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of episodes in this season.
|
||||
|
@ -124,29 +124,29 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The Studio that made this show.
|
||||
/// </summary>
|
||||
[LoadableRelation(nameof(StudioId))][EditableRelation] public Studio? Studio { get; set; }
|
||||
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of people that made this show.
|
||||
/// </summary>
|
||||
[LoadableRelation][EditableRelation] public ICollection<PeopleRole>? People { get; set; }
|
||||
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The different seasons in this show. If this is a movie, this list is always null or empty.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Season>? Seasons { get; set; }
|
||||
[SerializeIgnore] public ICollection<Season>? Seasons { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of episodes in this show.
|
||||
/// If this is a movie, there will be a unique episode (with the seasonNumber and episodeNumber set to null).
|
||||
/// Having an episode is necessary to store metadata and tracks.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Episode>? Episodes { get; set; }
|
||||
[SerializeIgnore] public ICollection<Episode>? Episodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of collections that contains this show.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Collection>? Collections { get; set; }
|
||||
[SerializeIgnore] public ICollection<Collection>? Collections { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The first episode of this show.
|
||||
|
@ -47,12 +47,12 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// The list of shows that are made by this studio.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Show>? Shows { get; set; }
|
||||
[SerializeIgnore] public ICollection<Show>? Shows { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of movies that are made by this studio.
|
||||
/// </summary>
|
||||
[LoadableRelation] public ICollection<Movie>? Movies { get; set; }
|
||||
[SerializeIgnore] public ICollection<Movie>? Movies { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
||||
|
@ -17,6 +17,7 @@
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
@ -59,7 +60,19 @@ public class Include<T>
|
||||
throw new ValidationException($"No loadable relation with the name {key}.");
|
||||
if (attr.RelationID != null)
|
||||
return new SingleRelation(prop.Name, prop.PropertyType, attr.RelationID);
|
||||
return new MultipleRelation(prop.Name);
|
||||
|
||||
// Multiples relations are disabled due to:
|
||||
// - Cartesian Explosions perfs
|
||||
// - Code complexity added.
|
||||
// if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) && prop.PropertyType != typeof(string))
|
||||
// {
|
||||
// // The property is either a list or a an array.
|
||||
// return new MultipleRelation(
|
||||
// prop.Name,
|
||||
// prop.PropertyType.GetElementType() ?? prop.PropertyType.GenericTypeArguments.First()
|
||||
// );
|
||||
// }
|
||||
throw new NotImplementedException();
|
||||
}).ToArray()
|
||||
};
|
||||
}
|
||||
@ -67,6 +80,4 @@ public class Include<T>
|
||||
public abstract record Metadata(string Name);
|
||||
|
||||
public record SingleRelation(string Name, Type type, string RelationIdName) : Metadata(Name);
|
||||
|
||||
public record MultipleRelation(string Name) : Metadata(Name);
|
||||
}
|
||||
|
@ -18,10 +18,17 @@
|
||||
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { KyooImage } from "@kyoo/models";
|
||||
import { H2, ImageBackground, Link, P, focusReset, ts } from "@kyoo/primitives";
|
||||
import {
|
||||
Collection,
|
||||
CollectionP,
|
||||
KyooImage,
|
||||
QueryIdentifier,
|
||||
useInfiniteFetch,
|
||||
} from "@kyoo/models";
|
||||
import { Container, H2, ImageBackground, Link, P, focusReset, ts } from "@kyoo/primitives";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Theme, useYoshiki } from "yoshiki/native";
|
||||
import { ErrorView, Fetch } from "../fetch";
|
||||
|
||||
export const PartOf = ({
|
||||
name,
|
||||
@ -69,3 +76,36 @@ export const PartOf = ({
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
export const DetailsCollections = ({ type, slug }: { type: "movie" | "show"; slug: string }) => {
|
||||
const { items, error } = useInfiniteFetch(DetailsCollections.query(type, slug));
|
||||
const { css } = useYoshiki();
|
||||
|
||||
if (error) return <ErrorView error={error} />;
|
||||
|
||||
// Since most items dont have collections, not having a skeleton reduces layout shifts.
|
||||
if (!items) return null;
|
||||
|
||||
return (
|
||||
<Container {...css({ marginY: ts(2) })}>
|
||||
{items.map((x) => (
|
||||
<PartOf
|
||||
key={x.id}
|
||||
name={x.name}
|
||||
overview={x.overview}
|
||||
thumbnail={x.thumbnail}
|
||||
href={x.href}
|
||||
/>
|
||||
))}
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
DetailsCollections.query = (type: "movie" | "show", slug: string): QueryIdentifier<Collection> => ({
|
||||
parser: CollectionP,
|
||||
path: [type, slug, "collections"],
|
||||
params: {
|
||||
limit: 0,
|
||||
},
|
||||
infinite: true,
|
||||
});
|
||||
|
@ -459,19 +459,6 @@ export const Header = ({
|
||||
</Chip>
|
||||
))}
|
||||
</Container>
|
||||
{data?.collections && (
|
||||
<Container {...css({ marginY: ts(2) })}>
|
||||
{data.collections.map((x) => (
|
||||
<PartOf
|
||||
key={x.id}
|
||||
name={x.name}
|
||||
overview={x.overview}
|
||||
thumbnail={x.thumbnail}
|
||||
href={x.href}
|
||||
/>
|
||||
))}
|
||||
</Container>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Fetch>
|
||||
|
@ -23,12 +23,13 @@ import { Platform, ScrollView } from "react-native";
|
||||
import { useYoshiki } from "yoshiki/native";
|
||||
import { DefaultLayout } from "../layout";
|
||||
import { Header } from "./header";
|
||||
import { DetailsCollections } from "./collection";
|
||||
|
||||
const query = (slug: string): QueryIdentifier<Movie> => ({
|
||||
parser: MovieP,
|
||||
path: ["movies", slug],
|
||||
params: {
|
||||
fields: ["studio", "collections"],
|
||||
fields: ["studio"],
|
||||
},
|
||||
});
|
||||
|
||||
@ -49,6 +50,7 @@ export const MovieDetails: QueryPage<{ slug: string }> = ({ slug }) => {
|
||||
)}
|
||||
>
|
||||
<Header type="movie" query={query(slug)} />
|
||||
<DetailsCollections type="movie" slug={slug} />
|
||||
{/* <Staff slug={slug} /> */}
|
||||
</ScrollView>
|
||||
);
|
||||
@ -56,6 +58,7 @@ export const MovieDetails: QueryPage<{ slug: string }> = ({ slug }) => {
|
||||
|
||||
MovieDetails.getFetchUrls = ({ slug }) => [
|
||||
query(slug),
|
||||
DetailsCollections.query("movie", slug),
|
||||
// ShowStaff.query(slug),
|
||||
];
|
||||
|
||||
|
@ -27,6 +27,7 @@ import { Header } from "./header";
|
||||
import Svg, { Path, SvgProps } from "react-native-svg";
|
||||
import { Container } from "@kyoo/primitives";
|
||||
import { forwardRef } from "react";
|
||||
import { DetailsCollections } from "./collection";
|
||||
|
||||
export const SvgWave = (props: SvgProps) => {
|
||||
const { css } = useYoshiki();
|
||||
@ -65,6 +66,7 @@ const ShowHeader = forwardRef<View, ViewProps & { slug: string }>(function ShowH
|
||||
)}
|
||||
>
|
||||
<Header type="show" query={query(slug)} />
|
||||
<DetailsCollections type="movie" slug={slug} />
|
||||
{/* <Staff slug={slug} /> */}
|
||||
<SvgWave
|
||||
fill={theme.variant.background}
|
||||
@ -96,6 +98,7 @@ export const ShowDetails: QueryPage<{ slug: string; season: string }> = ({ slug,
|
||||
|
||||
ShowDetails.getFetchUrls = ({ slug, season }) => [
|
||||
query(slug),
|
||||
DetailsCollections.query("show", slug),
|
||||
// ShowStaff.query(slug),
|
||||
EpisodeList.query(slug, season),
|
||||
SeasonHeader.query(slug),
|
||||
|
Loading…
x
Reference in New Issue
Block a user