From b79ed8a1985ed9517884764ef777e20efc58788c Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 2 Mar 2020 21:44:17 +0100 Subject: [PATCH] Solving a bug with collections --- Kyoo.Common/Models/Show.cs | 4 ++-- Kyoo/Controllers/Crawler.cs | 2 ++ Kyoo/Controllers/LibraryManager.cs | 19 ++++++++----------- Kyoo/Controllers/ProviderManager.cs | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Kyoo.Common/Models/Show.cs b/Kyoo.Common/Models/Show.cs index f377bd37..4453034d 100644 --- a/Kyoo.Common/Models/Show.cs +++ b/Kyoo.Common/Models/Show.cs @@ -60,7 +60,7 @@ namespace Kyoo.Models { Slug = slug; Title = title; - Aliases = aliases.ToArray(); + Aliases = aliases?.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; @@ -76,7 +76,7 @@ namespace Kyoo.Models { Slug = slug; Title = title; - Aliases = aliases.ToArray(); + Aliases = aliases?.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index 19957a09..afcc5684 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -93,6 +93,8 @@ namespace Kyoo.Controllers if (_libraryManager.RegisterEpisode(episode) == 0) return; } + if (collection != null) + _libraryManager.RegisterCollection(collection); _libraryManager.RegisterShowLinks(library, collection, show); } diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 2dfd306c..7966e34d 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -62,9 +62,7 @@ namespace Kyoo.Controllers public IEnumerable GetShows() { - return (from show in _database.Shows from l in _database.CollectionLinks.DefaultIfEmpty() - where l.CollectionID == null select show).AsEnumerable().Union( - from collection in _database.Collections select collection.AsShow()).OrderBy(x => x.Title); + return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow()); } public IEnumerable GetShows(string searchQuery) @@ -220,7 +218,10 @@ namespace Kyoo.Controllers public Collection GetCollection(string slug) { - return (from collection in _database.Collections where collection.Slug == slug select collection).FirstOrDefault(); + Collection collection = _database.Collections.Where(collection => collection.Slug == slug).FirstOrDefault(); + if (collection != null) + collection.Shows = GetShowsInCollection(collection.ID); + return collection; } public IEnumerable GetShowsInCollection(long collectionID) @@ -232,12 +233,7 @@ namespace Kyoo.Controllers { return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link) .AsEnumerable() - .Select(link => - { - _database.Entry(link).Reference(l => l.Show).Load(); - _database.Entry(link).Reference(l => l.Collection).Load(); - return link.Show ?? link.Collection.AsShow(); - }) + .Select(link => link.Show ?? link.Collection.AsShow()) .OrderBy(x => x.Title); } @@ -395,7 +391,8 @@ namespace Kyoo.Controllers _database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID}, x => x.LibraryID == library.ID && x.CollectionID == collection.ID && x.ShowID == null); _database.CollectionLinks.AddIfNotExist(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID}, x => x.CollectionID == collection.ID && x.ShowID == show.ID); } - _database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, ShowID = show.ID}, x => x.LibraryID == library.ID && x.CollectionID == null && x.ShowID == show.ID); + else + _database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, ShowID = show.ID}, x => x.LibraryID == library.ID && x.CollectionID == null && x.ShowID == show.ID); _database.SaveChanges(); } diff --git a/Kyoo/Controllers/ProviderManager.cs b/Kyoo/Controllers/ProviderManager.cs index 1dec849e..ca33d5ca 100644 --- a/Kyoo/Controllers/ProviderManager.cs +++ b/Kyoo/Controllers/ProviderManager.cs @@ -28,7 +28,7 @@ namespace Kyoo.Controllers if (library.Providers.Contains(provider.Name)) ret = ret.Merge(await providerCall(provider)); } catch (Exception ex) { - Console.Error.WriteLine($"The provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); + Console.Error.WriteLine($"\tThe provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); } } return ret; @@ -45,7 +45,7 @@ namespace Kyoo.Controllers if (library.Providers.Contains(provider.Name)) ret.AddRange(await providerCall(provider) ?? new List()); } catch (Exception ex) { - Console.Error.WriteLine($"The provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); + Console.Error.WriteLine($"\tThe provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); } } return ret;