Solving a small bug with reuse of objects

This commit is contained in:
Zoe Roux 2020-02-08 17:52:17 +01:00
parent ef7b2bb61b
commit d307308fb4
3 changed files with 15 additions and 9 deletions

View File

@ -28,6 +28,7 @@ namespace Kyoo.Controllers
Library GetLibrary(string librarySlug);
IEnumerable<Library> GetLibraries();
Show GetShowBySlug(string slug);
Show GetShow(string path);
Season GetSeason(string showSlug, long seasonNumber);
IEnumerable<Episode> GetEpisodes(string showSlug);
IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber);

View File

@ -132,25 +132,25 @@ namespace Kyoo.Controllers
{
if (string.IsNullOrEmpty(collectionName))
return await Task.FromResult<Collection>(null);
if (_libraryManager.IsCollectionRegistered(Utility.ToSlug(collectionName), out long collectionID))
return new Collection {ID = collectionID};
return await _metadataProvider.GetCollectionFromName(collectionName, library);
return _libraryManager.GetCollection(Utility.ToSlug(collectionName)) ?? await _metadataProvider.GetCollectionFromName(collectionName, library);
}
private async Task<Show> GetShow(string showTitle, string showPath, Library library)
{
if (_libraryManager.IsShowRegistered(showPath, out long showID))
return new Show { ID = showID, Title = showTitle, ExternalIDs = _libraryManager.GetShowExternalIDs(showID) };
Show show = await _metadataProvider.GetShowFromName(showTitle, showPath, library);
Show show = _libraryManager.GetShow(showPath);
if (show != null)
return show;
show = await _metadataProvider.GetShowFromName(showTitle, showPath, library);
show.People = from people in await _metadataProvider.GetPeople(show, library) select people.ToLink(show);
return show;
}
private async Task<Season> GetSeason(Show show, long seasonNumber, Library library)
{
if (_libraryManager.IsSeasonRegistered(show.ID, seasonNumber, out long seasonID))
return await Task.FromResult(new Season {ID = seasonID, ShowID = show.ID, Show = show});
Season season = await _metadataProvider.GetSeason(show, seasonNumber, library);
Season season = _libraryManager.GetSeason(show.Slug, seasonNumber);
if (season != null)
return await Task.FromResult(season);
season = await _metadataProvider.GetSeason(show, seasonNumber, library);
season.Show = show;
return season;
}

View File

@ -79,6 +79,11 @@ namespace Kyoo.Controllers
return (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault();
}
public Show GetShow(string path)
{
return (from show in _database.Shows where show.Path == path select show).FirstOrDefault();
}
public IEnumerable<Season> GetSeasons(long showID)
{
return from season in _database.Seasons where season.ShowID == showID select season;