mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Starting to use Lazy loading
This commit is contained in:
parent
46cfd6f3c7
commit
cbc10acf54
@ -25,7 +25,7 @@ namespace Kyoo.Models
|
||||
[JsonIgnore] public string ImgPrimary { get; set; }
|
||||
public string ExternalIDs { get; set; }
|
||||
|
||||
public IEnumerable<Track> Tracks { get; set; }
|
||||
public virtual IEnumerable<Track> Tracks { get; set; }
|
||||
|
||||
public string ShowTitle; //Used in the API response only
|
||||
public string Link; //Used in the API response only
|
||||
@ -73,6 +73,13 @@ namespace Kyoo.Models
|
||||
return showSlug + "-s" + seasonNumber + "e" + episodeNumber;
|
||||
}
|
||||
|
||||
public Episode SetLink(string showSlug)
|
||||
{
|
||||
Link = GetSlug(showSlug, SeasonNumber, EpisodeNumber);
|
||||
Thumb = "thumb/" + Link;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Episode Merge(Episode other)
|
||||
{
|
||||
if (other == null)
|
||||
|
13
Kyoo.Common/Models/GenreLink.cs
Normal file
13
Kyoo.Common/Models/GenreLink.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class GenreLink
|
||||
{
|
||||
// TODO Make json serializer ignore this class and only serialize the Genre child.
|
||||
// TODO include this class in the EF workflows.
|
||||
|
||||
public long ShowID { get; set; }
|
||||
public virtual Show Show { get; set; }
|
||||
public long GenreID { get; set; }
|
||||
public virtual Genre Genre { get; set; }
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ namespace Kyoo.Models
|
||||
{
|
||||
[JsonIgnore] public long ID { get; set; }
|
||||
[JsonIgnore] public long PeopleID { get; set; }
|
||||
public People People { get; set; }
|
||||
public virtual People People { get; set; }
|
||||
[JsonIgnore] public long ShowID { get; set; }
|
||||
[JsonIgnore] public Show Show { get; set; }
|
||||
[JsonIgnore] public virtual Show Show { get; set; }
|
||||
public string Role { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
|
@ -77,12 +77,12 @@ namespace Kyoo.Controllers
|
||||
public Show GetShowBySlug(string slug)
|
||||
{
|
||||
Show ret = (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault();
|
||||
if (ret == null)
|
||||
return null;
|
||||
// if (ret == null)
|
||||
// return null;
|
||||
//_database.Entry(ret).Collection(x => x.Genres).Load();
|
||||
_database.Entry(ret).Reference(x => x.Studio).Load();
|
||||
_database.Entry(ret).Collection(x => x.People).Load();
|
||||
_database.Entry(ret).Collection(x => x.Seasons).Load();
|
||||
// _database.Entry(ret).Reference(x => x.Studio).Load();
|
||||
// _database.Entry(ret).Collection(x => x.People).Load();
|
||||
// _database.Entry(ret).Collection(x => x.Seasons).Load();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -114,26 +114,26 @@ namespace Kyoo.Controllers
|
||||
|
||||
public IEnumerable<Episode> GetEpisodes(string showSlug)
|
||||
{
|
||||
return from episode in _database.Episodes where episode.Show.Slug == showSlug select episode;
|
||||
return from episode in _database.Episodes where episode.Show.Slug == showSlug select episode.SetLink(showSlug);
|
||||
}
|
||||
|
||||
public IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber)
|
||||
{
|
||||
return from episode in _database.Episodes where episode.SeasonNumber == seasonNumber
|
||||
&& episode.Show.Slug == showSlug select episode;
|
||||
&& episode.Show.Slug == showSlug select episode.SetLink(showSlug);
|
||||
}
|
||||
|
||||
public IEnumerable<Episode> GetEpisodes(long showID, long seasonNumber)
|
||||
{
|
||||
return from episode in _database.Episodes where episode.ShowID == showID
|
||||
&& episode.SeasonNumber == seasonNumber select episode;
|
||||
&& episode.SeasonNumber == seasonNumber select episode.SetLink(episode.Show.Slug);
|
||||
}
|
||||
|
||||
public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
|
||||
{
|
||||
return (from episode in _database.Episodes where episode.EpisodeNumber == episodeNumber
|
||||
&& episode.SeasonNumber == seasonNumber
|
||||
&& episode.Show.Slug == showSlug select episode).FirstOrDefault();
|
||||
&& episode.Show.Slug == showSlug select episode.SetLink(showSlug)).FirstOrDefault();
|
||||
}
|
||||
|
||||
public WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true)
|
||||
|
@ -30,6 +30,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
|
@ -33,7 +33,8 @@ namespace Kyoo
|
||||
services.AddControllers().AddNewtonsoftJson();
|
||||
services.AddHttpClient();
|
||||
|
||||
services.AddDbContext<DatabaseContext>(options => options.UseSqlite(Configuration.GetConnectionString("Database")));
|
||||
services.AddDbContext<DatabaseContext>(options => options.UseLazyLoadingProxies()
|
||||
.UseSqlite(Configuration.GetConnectionString("Database")));
|
||||
|
||||
// services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
// .AddEntityFrameworkStores()
|
||||
|
Loading…
x
Reference in New Issue
Block a user