Solving a bug with duplicated people in the database

This commit is contained in:
Zoe Roux 2020-02-12 00:34:42 +01:00
parent 4fa5655178
commit 862b4a42a7
7 changed files with 13 additions and 21 deletions

View File

@ -15,7 +15,7 @@ namespace Kyoo.Controllers
int GetSeasonCount(string showSlug, long seasonNumber);
IEnumerable<Show> GetShowsInCollection(long collectionID);
IEnumerable<Show> GetShowsInLibrary(long libraryID);
IEnumerable<Show> GetShowsByPeople(long peopleID);
IEnumerable<Show> GetShowsByPeople(string peopleSlug);
IEnumerable<string> GetLibrariesPath();
//Internal read

View File

@ -5,7 +5,6 @@ namespace Kyoo.Models
{
public class People : IMergable<People>
{
[JsonIgnore] public long ID { get; set; }
public string Slug { get; set; }
public string Name { get; set; }
[JsonIgnore] public string ImgPrimary { get; set; }
@ -27,8 +26,6 @@ namespace Kyoo.Models
{
if (other == null)
return this;
if (ID == -1)
ID = other.ID;
if (Slug == null)
Slug = other.Slug;
if (Name == null)

View File

@ -5,7 +5,7 @@ namespace Kyoo.Models
public class PeopleLink
{
[JsonIgnore] public long ID { get; set; }
[JsonIgnore] public long PeopleID { get; set; }
[JsonIgnore] public string PeopleID { get; set; }
[JsonIgnore] public virtual People People { get; set; }
public string Slug => People.Slug;

View File

@ -120,7 +120,11 @@ namespace Kyoo.Controllers
if (show != null)
return show;
show = await _metadataProvider.GetShowFromName(showTitle, showPath, library);
show.People = (from people in await _metadataProvider.GetPeople(show, library) select people).ToList();
show.People = (await _metadataProvider.GetPeople(show, library)).Select(x =>
{
People existing = _libraryManager.GetPeopleBySlug(x.Slug);
return existing != null ? new PeopleLink(existing, x.Role, x.Type) : x;
}).ToList();
return show;
}

View File

@ -218,9 +218,9 @@ namespace Kyoo.Controllers
.OrderBy(x => x.Title);
}
public IEnumerable<Show> GetShowsByPeople(long peopleID)
public IEnumerable<Show> GetShowsByPeople(string peopleSlug)
{
return (from link in _database.PeopleLinks where link.PeopleID == peopleID select link.Show).OrderBy(x => x.Title);
return (from link in _database.PeopleLinks where link.PeopleID == peopleSlug select link.Show).OrderBy(x => x.Title);
}
public IEnumerable<Episode> GetAllEpisodes()
@ -305,18 +305,6 @@ namespace Kyoo.Controllers
_database.SaveChanges();
return studio.ID;
}
public long GetOrCreatePeople(People people)
{
People existingPeople = GetPeopleBySlug(people.Slug);
if (existingPeople != null)
return existingPeople.ID;
_database.Peoples.Add(people);
_database.SaveChanges();
return people.ID;
}
#endregion
#region Write Into The Database

View File

@ -52,6 +52,9 @@ namespace Kyoo
modelBuilder.Entity<Track>()
.Property(t => t.IsForced)
.ValueGeneratedNever();
modelBuilder.Entity<People>()
.HasKey(x => x.Slug);
modelBuilder.Entity<GenreLink>()
.HasKey(x => new {x.ShowID, x.GenreID});

View File

@ -24,7 +24,7 @@ namespace Kyoo.Api
return NotFound();
Collection collection = new Collection(people.Slug, people.Name, null, null)
{
Shows = _libraryManager.GetShowsByPeople(people.ID),
Shows = _libraryManager.GetShowsByPeople(people.Slug),
Poster = "peopleimg/" + people.Slug
};
return collection;