Fixed: History being lost per Track on Merge

pull/1056/head
Qstick 5 years ago
parent 6060270f14
commit c39eaabb14

@ -16,6 +16,7 @@ namespace NzbDrone.Core.History
List<History> FindByDownloadId(string downloadId);
List<History> GetByArtist(int artistId, HistoryEventType? eventType);
List<History> GetByAlbum(int albumId, HistoryEventType? eventType);
List<History> GetByTrack(int trackId, HistoryEventType? eventType);
List<History> FindDownloadHistory(int idArtistId, QualityModel quality);
void DeleteForArtist(int artistId);
void DeleteForAlbum(int albumId);
@ -83,6 +84,21 @@ namespace NzbDrone.Core.History
return query;
}
public List<History> GetByTrack(int trackId, HistoryEventType? eventType)
{
var query = Query.Join<History, Track>(JoinType.Inner, h => h.Track, (h, e) => h.TrackId == e.Id)
.Where(h => h.TrackId == trackId);
if (eventType.HasValue)
{
query.AndWhere(h => h.EventType == eventType);
}
query.OrderByDescending(h => h.Date);
return query;
}
public List<History> FindDownloadHistory(int idArtistId, QualityModel quality)
{
return Query.Where(h =>

@ -24,6 +24,7 @@ namespace NzbDrone.Core.History
History Get(int historyId);
List<History> GetByArtist(int artistId, HistoryEventType? eventType);
List<History> GetByAlbum(int albumId, HistoryEventType? eventType);
List<History> GetByTrack(int trackId, HistoryEventType? eventType);
List<History> Find(string downloadId, HistoryEventType eventType);
List<History> FindByDownloadId(string downloadId);
List<History> Since(DateTime date, HistoryEventType? eventType);
@ -82,6 +83,11 @@ namespace NzbDrone.Core.History
return _historyRepository.GetByAlbum(albumId, eventType);
}
public List<History> GetByTrack(int trackId, HistoryEventType? eventType)
{
return _historyRepository.GetByTrack(trackId, eventType);
}
public List<History> Find(string downloadId, HistoryEventType eventType)
{
return _historyRepository.FindByDownloadId(downloadId).Where(c => c.EventType == eventType).ToList();

@ -1,4 +1,5 @@
using NLog;
using NzbDrone.Core.History;
using NzbDrone.Core.MediaFiles;
using System;
using System.Collections.Generic;
@ -15,14 +16,17 @@ namespace NzbDrone.Core.Music
{
private readonly ITrackService _trackService;
private readonly IAudioTagService _audioTagService;
private readonly IHistoryService _historyService;
private readonly Logger _logger;
public RefreshTrackService(ITrackService trackService,
IAudioTagService audioTagService,
IHistoryService historyService,
Logger logger)
{
_trackService = trackService;
_audioTagService = audioTagService;
_historyService = historyService;
_logger = logger;
}
@ -52,6 +56,10 @@ namespace NzbDrone.Core.Music
mergeTarget.TrackFileId = trackToMerge.TrackFileId;
}
var items = _historyService.GetByTrack(trackToMerge.Id, null);
items.ForEach(x => x.TrackId = mergeTarget.Id);
_historyService.UpdateMany(items);
if (!updateList.Contains(mergeTarget))
{
updateList.Add(mergeTarget);

Loading…
Cancel
Save