mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-20 18:02:44 +01:00
Fixed: Don't die when adding existing exclusions
This commit is contained in:
parent
3a9b276c43
commit
9ef031bd9e
@ -1,4 +1,6 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Dapper;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
|
||||||
@ -8,6 +10,7 @@ public interface IImportExclusionsRepository : IBasicRepository<ImportExclusion>
|
|||||||
{
|
{
|
||||||
bool IsMovieExcluded(int tmdbid);
|
bool IsMovieExcluded(int tmdbid);
|
||||||
ImportExclusion GetByTmdbid(int tmdbid);
|
ImportExclusion GetByTmdbid(int tmdbid);
|
||||||
|
List<int> AllExcludedTmdbIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ImportExclusionsRepository : BasicRepository<ImportExclusion>, IImportExclusionsRepository
|
public class ImportExclusionsRepository : BasicRepository<ImportExclusion>, IImportExclusionsRepository
|
||||||
@ -26,5 +29,12 @@ public ImportExclusion GetByTmdbid(int tmdbid)
|
|||||||
{
|
{
|
||||||
return Query(x => x.TmdbId == tmdbid).First();
|
return Query(x => x.TmdbId == tmdbid).First();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<int> AllExcludedTmdbIds()
|
||||||
|
{
|
||||||
|
using var conn = _database.OpenConnection();
|
||||||
|
|
||||||
|
return conn.Query<int>("SELECT \"TmdbId\" FROM \"ImportExclusions\"").ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public ImportExclusion AddExclusion(ImportExclusion exclusion)
|
|||||||
|
|
||||||
public List<ImportExclusion> AddExclusions(List<ImportExclusion> exclusions)
|
public List<ImportExclusion> AddExclusions(List<ImportExclusion> exclusions)
|
||||||
{
|
{
|
||||||
_exclusionRepository.InsertMany(exclusions);
|
_exclusionRepository.InsertMany(DeDupeExclusions(exclusions));
|
||||||
|
|
||||||
return exclusions;
|
return exclusions;
|
||||||
}
|
}
|
||||||
@ -76,8 +76,20 @@ public void HandleAsync(MoviesDeletedEvent message)
|
|||||||
if (message.AddExclusion)
|
if (message.AddExclusion)
|
||||||
{
|
{
|
||||||
_logger.Debug("Adding {0} Deleted Movies to Import Exclusions", message.Movies.Count);
|
_logger.Debug("Adding {0} Deleted Movies to Import Exclusions", message.Movies.Count);
|
||||||
_exclusionRepository.InsertMany(message.Movies.Select(m => new ImportExclusion { TmdbId = m.TmdbId, MovieTitle = m.Title, MovieYear = m.Year }).ToList());
|
|
||||||
|
var exclusions = message.Movies.Select(m => new ImportExclusion { TmdbId = m.TmdbId, MovieTitle = m.Title, MovieYear = m.Year }).ToList();
|
||||||
|
_exclusionRepository.InsertMany(DeDupeExclusions(exclusions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ImportExclusion> DeDupeExclusions(List<ImportExclusion> exclusions)
|
||||||
|
{
|
||||||
|
var existingExclusions = _exclusionRepository.AllExcludedTmdbIds();
|
||||||
|
|
||||||
|
return exclusions
|
||||||
|
.DistinctBy(x => x.TmdbId)
|
||||||
|
.Where(x => !existingExclusions.Contains(x.TmdbId))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user