mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -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>
|
/// <summary>
|
||||||
/// The list of movies contained in this collection.
|
/// The list of movies contained in this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Movie>? Movies { get; set; }
|
[SerializeIgnore] public ICollection<Movie>? Movies { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of shows contained in this collection.
|
/// The list of shows contained in this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Show>? Shows { get; set; }
|
[SerializeIgnore] public ICollection<Show>? Shows { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
||||||
|
@ -123,17 +123,17 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Studio that made this show.
|
/// The Studio that made this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation(nameof(StudioId))][EditableRelation] public Studio? Studio { get; set; }
|
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of people that made this show.
|
/// The list of people that made this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation][EditableRelation] public ICollection<PeopleRole>? People { get; set; }
|
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of collections that contains this show.
|
/// The list of collections that contains this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Collection>? Collections { get; set; }
|
[SerializeIgnore] public ICollection<Collection>? Collections { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Links to watch this movie.
|
/// Links to watch this movie.
|
||||||
|
@ -61,7 +61,7 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of roles this person has played in. See <see cref="PeopleRole"/> for more information.
|
/// The list of roles this person has played in. See <see cref="PeopleRole"/> for more information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EditableRelation][LoadableRelation] public ICollection<PeopleRole>? Roles { get; set; }
|
[SerializeIgnore] public ICollection<PeopleRole>? Roles { get; set; }
|
||||||
|
|
||||||
public People() { }
|
public People() { }
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of episodes that this season contains.
|
/// The list of episodes that this season contains.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Episode>? Episodes { get; set; }
|
[SerializeIgnore] public ICollection<Episode>? Episodes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The number of episodes in this season.
|
/// The number of episodes in this season.
|
||||||
|
@ -124,29 +124,29 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Studio that made this show.
|
/// The Studio that made this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation(nameof(StudioId))][EditableRelation] public Studio? Studio { get; set; }
|
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of people that made this show.
|
/// The list of people that made this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation][EditableRelation] public ICollection<PeopleRole>? People { get; set; }
|
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The different seasons in this show. If this is a movie, this list is always null or empty.
|
/// The different seasons in this show. If this is a movie, this list is always null or empty.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Season>? Seasons { get; set; }
|
[SerializeIgnore] public ICollection<Season>? Seasons { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of episodes in this show.
|
/// 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).
|
/// 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.
|
/// Having an episode is necessary to store metadata and tracks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Episode>? Episodes { get; set; }
|
[SerializeIgnore] public ICollection<Episode>? Episodes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of collections that contains this show.
|
/// The list of collections that contains this show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Collection>? Collections { get; set; }
|
[SerializeIgnore] public ICollection<Collection>? Collections { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The first episode of this show.
|
/// The first episode of this show.
|
||||||
|
@ -47,12 +47,12 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of shows that are made by this studio.
|
/// The list of shows that are made by this studio.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Show>? Shows { get; set; }
|
[SerializeIgnore] public ICollection<Show>? Shows { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of movies that are made by this studio.
|
/// The list of movies that are made by this studio.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LoadableRelation] public ICollection<Movie>? Movies { get; set; }
|
[SerializeIgnore] public ICollection<Movie>? Movies { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -59,7 +60,19 @@ public class Include<T>
|
|||||||
throw new ValidationException($"No loadable relation with the name {key}.");
|
throw new ValidationException($"No loadable relation with the name {key}.");
|
||||||
if (attr.RelationID != null)
|
if (attr.RelationID != null)
|
||||||
return new SingleRelation(prop.Name, prop.PropertyType, attr.RelationID);
|
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()
|
}).ToArray()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -67,6 +80,4 @@ public class Include<T>
|
|||||||
public abstract record Metadata(string Name);
|
public abstract record Metadata(string Name);
|
||||||
|
|
||||||
public record SingleRelation(string Name, Type type, string RelationIdName) : Metadata(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/>.
|
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { KyooImage } from "@kyoo/models";
|
import {
|
||||||
import { H2, ImageBackground, Link, P, focusReset, ts } from "@kyoo/primitives";
|
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 { useTranslation } from "react-i18next";
|
||||||
import { Theme, useYoshiki } from "yoshiki/native";
|
import { Theme, useYoshiki } from "yoshiki/native";
|
||||||
|
import { ErrorView, Fetch } from "../fetch";
|
||||||
|
|
||||||
export const PartOf = ({
|
export const PartOf = ({
|
||||||
name,
|
name,
|
||||||
@ -69,3 +76,36 @@ export const PartOf = ({
|
|||||||
</Link>
|
</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>
|
</Chip>
|
||||||
))}
|
))}
|
||||||
</Container>
|
</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>
|
</Fetch>
|
||||||
|
@ -23,12 +23,13 @@ import { Platform, ScrollView } from "react-native";
|
|||||||
import { useYoshiki } from "yoshiki/native";
|
import { useYoshiki } from "yoshiki/native";
|
||||||
import { DefaultLayout } from "../layout";
|
import { DefaultLayout } from "../layout";
|
||||||
import { Header } from "./header";
|
import { Header } from "./header";
|
||||||
|
import { DetailsCollections } from "./collection";
|
||||||
|
|
||||||
const query = (slug: string): QueryIdentifier<Movie> => ({
|
const query = (slug: string): QueryIdentifier<Movie> => ({
|
||||||
parser: MovieP,
|
parser: MovieP,
|
||||||
path: ["movies", slug],
|
path: ["movies", slug],
|
||||||
params: {
|
params: {
|
||||||
fields: ["studio", "collections"],
|
fields: ["studio"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ export const MovieDetails: QueryPage<{ slug: string }> = ({ slug }) => {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Header type="movie" query={query(slug)} />
|
<Header type="movie" query={query(slug)} />
|
||||||
|
<DetailsCollections type="movie" slug={slug} />
|
||||||
{/* <Staff slug={slug} /> */}
|
{/* <Staff slug={slug} /> */}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
@ -56,6 +58,7 @@ export const MovieDetails: QueryPage<{ slug: string }> = ({ slug }) => {
|
|||||||
|
|
||||||
MovieDetails.getFetchUrls = ({ slug }) => [
|
MovieDetails.getFetchUrls = ({ slug }) => [
|
||||||
query(slug),
|
query(slug),
|
||||||
|
DetailsCollections.query("movie", slug),
|
||||||
// ShowStaff.query(slug),
|
// ShowStaff.query(slug),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import { Header } from "./header";
|
|||||||
import Svg, { Path, SvgProps } from "react-native-svg";
|
import Svg, { Path, SvgProps } from "react-native-svg";
|
||||||
import { Container } from "@kyoo/primitives";
|
import { Container } from "@kyoo/primitives";
|
||||||
import { forwardRef } from "react";
|
import { forwardRef } from "react";
|
||||||
|
import { DetailsCollections } from "./collection";
|
||||||
|
|
||||||
export const SvgWave = (props: SvgProps) => {
|
export const SvgWave = (props: SvgProps) => {
|
||||||
const { css } = useYoshiki();
|
const { css } = useYoshiki();
|
||||||
@ -65,6 +66,7 @@ const ShowHeader = forwardRef<View, ViewProps & { slug: string }>(function ShowH
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Header type="show" query={query(slug)} />
|
<Header type="show" query={query(slug)} />
|
||||||
|
<DetailsCollections type="movie" slug={slug} />
|
||||||
{/* <Staff slug={slug} /> */}
|
{/* <Staff slug={slug} /> */}
|
||||||
<SvgWave
|
<SvgWave
|
||||||
fill={theme.variant.background}
|
fill={theme.variant.background}
|
||||||
@ -96,6 +98,7 @@ export const ShowDetails: QueryPage<{ slug: string; season: string }> = ({ slug,
|
|||||||
|
|
||||||
ShowDetails.getFetchUrls = ({ slug, season }) => [
|
ShowDetails.getFetchUrls = ({ slug, season }) => [
|
||||||
query(slug),
|
query(slug),
|
||||||
|
DetailsCollections.query("show", slug),
|
||||||
// ShowStaff.query(slug),
|
// ShowStaff.query(slug),
|
||||||
EpisodeList.query(slug, season),
|
EpisodeList.query(slug, season),
|
||||||
SeasonHeader.query(slug),
|
SeasonHeader.query(slug),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user