Skip to content

Commit

Permalink
fix: ensure only 1 xref per company exist
Browse files Browse the repository at this point in the history
Closes #1191
  • Loading branch information
revam committed Oct 25, 2024
1 parent 3013fcf commit 991ac1c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,16 +1931,18 @@ private void PurgeTitlesAndOverviews(ForeignEntityType foreignType, int foreignI
private async Task<bool> UpdateCompanies(IEntityMetadata tmdbEntity, List<ProductionCompany> companies)
{
var existingXrefs = _xrefTmdbCompanyEntity.GetByTmdbEntityTypeAndID(tmdbEntity.Type, tmdbEntity.Id)
.ToDictionary(xref => xref.TmdbCompanyID);
.GroupBy(xref => xref.TmdbCompanyID)
.ToDictionary(xref => xref.Key, groupBy => groupBy.ToList());
var xrefsToAdd = 0;
var xrefsToSkip = new HashSet<int>();
var xrefsToSave = new List<TMDB_Company_Entity>();
var indexCounter = 0;
foreach (var company in companies)
{
var currentIndex = indexCounter++;
if (existingXrefs.TryGetValue(company.Id, out var existingXref))
if (existingXrefs.TryGetValue(company.Id, out var existingXrefList))
{
var existingXref = existingXrefList[0];
if (existingXref.Ordering != currentIndex || existingXref.ReleasedAt != tmdbEntity.ReleasedAt)
{
existingXref.Ordering = currentIndex;
Expand All @@ -1958,6 +1960,7 @@ private async Task<bool> UpdateCompanies(IEntityMetadata tmdbEntity, List<Produc
await UpdateCompany(company);
}
var xrefsToRemove = existingXrefs.Values
.SelectMany(xrefs => xrefs)
.ExceptBy(xrefsToSkip, o => o.TMDB_Company_EntityID)
.ToList();

Expand Down

0 comments on commit 991ac1c

Please sign in to comment.