Making merge of lists work well

This commit is contained in:
Zoe Roux 2020-02-29 21:38:39 +01:00
parent 7e873aaed5
commit e2f76b62e2
4 changed files with 25 additions and 3 deletions

View File

@ -48,7 +48,7 @@ namespace Kyoo.Models
Overview = collection.Overview;
if (ImgPrimary == null)
ImgPrimary = collection.ImgPrimary;
Shows = Shows == null ? collection.Shows : Shows.Concat(collection.Shows);
Shows = Utility.MergeLists(Shows, collection.Shows, (x, y) => x.Slug == y.Slug);
return this;
}
}

View File

@ -109,8 +109,8 @@ namespace Kyoo.Models
ID = other.ID;
Slug ??= other.Slug;
Title ??= other.Title;
Aliases = Aliases == null ? other.Aliases : Aliases.Concat(other.Aliases).ToArray();
Genres = Genres == null ? other.Genres : Genres.Concat(other.Genres);
Aliases = Utility.MergeLists(Aliases, other.Aliases).ToArray();
Genres = Utility.MergeLists(Genres, other.Genres, (x, y) => x.Slug == y.Slug);
Path ??= other.Path;
Overview ??= other.Overview;
TrailerUrl ??= other.TrailerUrl;
@ -121,6 +121,8 @@ namespace Kyoo.Models
ImgThumb ??= other.ImgThumb;
ImgLogo ??= other.ImgLogo;
ImgBackdrop ??= other.ImgBackdrop;
if (other.Studio != null)
Studio ??= other.Studio;
ExternalIDs = string.Join('|', ExternalIDs, other.ExternalIDs);
return this;
}

View File

@ -1,3 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Kyoo.Models;
@ -58,5 +62,17 @@ namespace Kyoo
break;
}
}
public static IEnumerable<T> MergeLists<T>(IEnumerable<T> first, IEnumerable<T> second, Func<T, T, bool> isEqual = null)
{
if (first == null)
return second;
if (second == null)
return first;
List<T> list = first.ToList();
if (isEqual == null)
isEqual = (x, y) => x.Equals(y);
return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y))));
}
}
}

View File

@ -16,6 +16,10 @@
<StartupObject>Kyoo.Program</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin/Release/</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="3.1.2" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.2" />