mirror of
https://github.com/Radarr/Radarr
synced 2025-02-24 07:10:57 +00:00
Fixed: Duplicates on index before housekeeper runs when manual importing over existing file
This commit is contained in:
parent
005ad00caf
commit
9442666493
5 changed files with 22 additions and 80 deletions
|
@ -70,84 +70,5 @@ public void should_get_download_history()
|
|||
|
||||
downloadHistory.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_movie_history()
|
||||
{
|
||||
var historyMovie1 = Builder<MovieHistory>.CreateNew()
|
||||
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(c => c.Languages = new List<Language> { Language.English })
|
||||
.With(c => c.MovieId = 12)
|
||||
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
|
||||
.BuildNew();
|
||||
|
||||
var historyMovie2 = Builder<MovieHistory>.CreateNew()
|
||||
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(c => c.Languages = new List<Language> { Language.English })
|
||||
.With(c => c.MovieId = 13)
|
||||
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
|
||||
.BuildNew();
|
||||
|
||||
Subject.Insert(historyMovie1);
|
||||
Subject.Insert(historyMovie2);
|
||||
|
||||
var movieHistory = Subject.GetByMovieId(12, null);
|
||||
|
||||
movieHistory.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_sort_movie_history_by_date()
|
||||
{
|
||||
var historyFirst = Builder<MovieHistory>.CreateNew()
|
||||
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(c => c.Languages = new List<Language> { Language.English })
|
||||
.With(c => c.MovieId = 12)
|
||||
.With(c => c.EventType = MovieHistoryEventType.MovieFileRenamed)
|
||||
.With(c => c.Date = DateTime.UtcNow)
|
||||
.BuildNew();
|
||||
|
||||
var historySecond = Builder<MovieHistory>.CreateNew()
|
||||
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(c => c.Languages = new List<Language> { Language.English })
|
||||
.With(c => c.MovieId = 12)
|
||||
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
|
||||
.With(c => c.Date = DateTime.UtcNow.AddMinutes(10))
|
||||
.BuildNew();
|
||||
|
||||
Subject.Insert(historyFirst);
|
||||
Subject.Insert(historySecond);
|
||||
|
||||
var movieHistory = Subject.GetByMovieId(12, null);
|
||||
|
||||
movieHistory.Should().HaveCount(2);
|
||||
movieHistory.First().EventType.Should().Be(MovieHistoryEventType.Grabbed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_history_items_by_movieId()
|
||||
{
|
||||
var items = Builder<MovieHistory>.CreateListOfSize(5)
|
||||
.TheFirst(1)
|
||||
.With(c => c.MovieId = _movie2.Id)
|
||||
.TheRest()
|
||||
.With(c => c.MovieId = _movie1.Id)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(c => c.Languages = new List<Language> { Language.English })
|
||||
.With(c => c.EventType = MovieHistoryEventType.Grabbed)
|
||||
.BuildListOfNew();
|
||||
|
||||
Db.InsertMany(items);
|
||||
|
||||
Subject.DeleteForMovies(new List<int> { _movie1.Id });
|
||||
|
||||
var removedItems = Subject.GetByMovieId(_movie1.Id, null);
|
||||
var nonRemovedItems = Subject.GetByMovieId(_movie2.Id, null);
|
||||
|
||||
removedItems.Should().HaveCount(0);
|
||||
nonRemovedItems.Should().HaveCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ public interface IMediaFileRepository : IBasicRepository<MovieFile>
|
|||
List<MovieFile> GetFilesByMovie(int movieId);
|
||||
List<MovieFile> GetFilesWithoutMediaInfo();
|
||||
void DeleteForMovies(List<int> movieIds);
|
||||
|
||||
List<MovieFile> GetFilesWithRelativePath(int movieId, string relativePath);
|
||||
}
|
||||
|
||||
public class MediaFileRepository : BasicRepository<MovieFile>, IMediaFileRepository
|
||||
|
@ -32,5 +34,10 @@ public void DeleteForMovies(List<int> movieIds)
|
|||
{
|
||||
Delete(x => movieIds.Contains(x.MovieId));
|
||||
}
|
||||
|
||||
public List<MovieFile> GetFilesWithRelativePath(int movieId, string relativePath)
|
||||
{
|
||||
return Query(c => c.MovieId == movieId && c.RelativePath == relativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public interface IMediaFileService
|
|||
List<string> FilterExistingFiles(List<string> files, Movie movie);
|
||||
MovieFile GetMovie(int id);
|
||||
List<MovieFile> GetMovies(IEnumerable<int> ids);
|
||||
List<MovieFile> GetFilesWithRelativePath(int movieIds, string relativePath);
|
||||
}
|
||||
|
||||
public class MediaFileService : IMediaFileService, IHandleAsync<MoviesDeletedEvent>
|
||||
|
@ -106,6 +107,11 @@ public MovieFile GetMovie(int id)
|
|||
return _mediaFileRepository.Get(id);
|
||||
}
|
||||
|
||||
public List<MovieFile> GetFilesWithRelativePath(int movieId, string relativePath)
|
||||
{
|
||||
return _mediaFileRepository.GetFilesWithRelativePath(movieId, relativePath);
|
||||
}
|
||||
|
||||
public void HandleAsync(MoviesDeletedEvent message)
|
||||
{
|
||||
_mediaFileRepository.DeleteForMovies(message.Movies.Select(m => m.Id).ToList());
|
||||
|
|
|
@ -126,6 +126,14 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
|||
else
|
||||
{
|
||||
movieFile.RelativePath = localMovie.Movie.Path.GetRelativePath(movieFile.Path);
|
||||
|
||||
// Delete existing files from the DB mapped to this path
|
||||
var previousFiles = _mediaFileService.GetFilesWithRelativePath(localMovie.Movie.Id, movieFile.RelativePath);
|
||||
|
||||
foreach (var previousFile in previousFiles)
|
||||
{
|
||||
_mediaFileService.Delete(previousFile, DeleteMediaFileReason.ManualOverride);
|
||||
}
|
||||
}
|
||||
|
||||
movieFile = _mediaFileService.Add(movieFile);
|
||||
|
|
|
@ -95,7 +95,7 @@ public override IEnumerable<Movie> All()
|
|||
// the skips the join on profile and alternative title and populates manually
|
||||
// to avoid repeatedly deserializing the same profile / movie
|
||||
var builder = new SqlBuilder()
|
||||
.LeftJoin<Movie, MovieFile>((m, f) => m.Id == f.MovieId);
|
||||
.LeftJoin<Movie, MovieFile>((m, f) => m.MovieFileId == f.Id);
|
||||
|
||||
var profiles = _profileRepository.All().ToDictionary(x => x.Id);
|
||||
var titles = _alternativeTitleRepository.All()
|
||||
|
|
Loading…
Reference in a new issue