Fixed: Frontend updates when selected album release changed

pull/891/head
ta264 5 years ago
parent dcca2b5a1a
commit 1dcccf2683

@ -5,16 +5,19 @@ namespace NzbDrone.Core.MediaFiles.Commands
public class RescanArtistCommand : Command public class RescanArtistCommand : Command
{ {
public int? ArtistId { get; set; } public int? ArtistId { get; set; }
public FilterFilesType Filter { get; set; }
public override bool SendUpdatesToClient => true; public override bool SendUpdatesToClient => true;
public RescanArtistCommand() public RescanArtistCommand(FilterFilesType filter = FilterFilesType.Known)
{ {
Filter = filter;
} }
public RescanArtistCommand(int artistId) public RescanArtistCommand(int artistId, FilterFilesType filter = FilterFilesType.Known)
{ {
ArtistId = artistId; ArtistId = artistId;
Filter = filter;
} }
} }
} }

@ -275,7 +275,7 @@ namespace NzbDrone.Core.MediaFiles
if (message.ArtistId.HasValue) if (message.ArtistId.HasValue)
{ {
var artist = _artistService.GetArtist(message.ArtistId.Value); var artist = _artistService.GetArtist(message.ArtistId.Value);
Scan(artist); Scan(artist, message.Filter);
} }
else else
@ -284,7 +284,7 @@ namespace NzbDrone.Core.MediaFiles
foreach (var artist in allArtists) foreach (var artist in allArtists)
{ {
Scan(artist); Scan(artist, message.Filter);
} }
} }
} }

@ -102,7 +102,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
// set the correct release to be monitored before importing the new files // set the correct release to be monitored before importing the new files
_logger.Debug("Updating release to {0} [{1} tracks]", newRelease, newRelease.TrackCount); _logger.Debug("Updating release to {0} [{1} tracks]", newRelease, newRelease.TrackCount);
_releaseService.SetMonitored(newRelease); album.AlbumReleases = _releaseService.SetMonitored(newRelease);
// Publish album edited event. // Publish album edited event.
// Deliberatly don't put in the old album since we don't want to trigger an ArtistScan. // Deliberatly don't put in the old album since we don't want to trigger an ArtistScan.
@ -111,6 +111,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
var filesToAdd = new List<TrackFile>(qualifiedImports.Count); var filesToAdd = new List<TrackFile>(qualifiedImports.Count);
var albumReleasesDict = new Dictionary<int, List<AlbumRelease>>(albumDecisions.Count); var albumReleasesDict = new Dictionary<int, List<AlbumRelease>>(albumDecisions.Count);
var trackImportedEvents = new List<TrackImportedEvent>(qualifiedImports.Count);
foreach (var importDecision in qualifiedImports.OrderBy(e => e.Item.Tracks.Select(track => track.AbsoluteTrackNumber).MinOrDefault()) foreach (var importDecision in qualifiedImports.OrderBy(e => e.Item.Tracks.Select(track => track.AbsoluteTrackNumber).MinOrDefault())
.ThenByDescending(e => e.Item.Size)) .ThenByDescending(e => e.Item.Size))
@ -209,7 +210,9 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
allImportedTrackFiles.Add(trackFile); allImportedTrackFiles.Add(trackFile);
allOldTrackFiles.AddRange(oldFiles); allOldTrackFiles.AddRange(oldFiles);
_eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, oldFiles, !localTrack.ExistingFile, downloadClientItem)); // create all the import events here, but we can't publish until the trackfiles have been
// inserted and ids created
trackImportedEvents.Add(new TrackImportedEvent(localTrack, trackFile, oldFiles, !localTrack.ExistingFile, downloadClientItem));
} }
catch (RootFolderNotFoundException e) catch (RootFolderNotFoundException e)
{ {
@ -245,6 +248,12 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
_trackService.SetFileIds(filesToAdd.SelectMany(x => x.Tracks.Value).ToList()); _trackService.SetFileIds(filesToAdd.SelectMany(x => x.Tracks.Value).ToList());
_logger.Debug($"TrackFileIds updated, total {watch.ElapsedMilliseconds}ms"); _logger.Debug($"TrackFileIds updated, total {watch.ElapsedMilliseconds}ms");
// now that trackfiles have been inserted and ids generated, publish the import events
foreach (var trackImportedEvent in trackImportedEvents)
{
_eventAggregator.PublishEvent(trackImportedEvent);
}
var albumImports = importResults.Where(e => e.ImportDecision.Item.Album != null) var albumImports = importResults.Where(e => e.ImportDecision.Item.Album != null)
.GroupBy(e => e.ImportDecision.Item.Album.Id).ToList(); .GroupBy(e => e.ImportDecision.Item.Album.Id).ToList();

@ -4,16 +4,20 @@ using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Music.Events; using NzbDrone.Core.Music.Events;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.MediaFiles;
namespace NzbDrone.Core.Music namespace NzbDrone.Core.Music
{ {
public class AlbumEditedService : IHandle<AlbumEditedEvent> public class AlbumEditedService : IHandle<AlbumEditedEvent>
{ {
private readonly IManageCommandQueue _commandQueueManager; private readonly IManageCommandQueue _commandQueueManager;
private readonly ITrackService _trackService;
public AlbumEditedService(IManageCommandQueue commandQueueManager) public AlbumEditedService(IManageCommandQueue commandQueueManager,
ITrackService trackService)
{ {
_commandQueueManager = commandQueueManager; _commandQueueManager = commandQueueManager;
_trackService = trackService;
} }
public void Handle(AlbumEditedEvent message) public void Handle(AlbumEditedEvent message)
@ -25,7 +29,12 @@ namespace NzbDrone.Core.Music
if (!new_monitored.SetEquals(old_monitored) || if (!new_monitored.SetEquals(old_monitored) ||
(message.OldAlbum.AnyReleaseOk == false && message.Album.AnyReleaseOk == true)) (message.OldAlbum.AnyReleaseOk == false && message.Album.AnyReleaseOk == true))
{ {
_commandQueueManager.Push(new RescanArtistCommand(message.Album.ArtistId)); // Unlink any old track files
var tracks = _trackService.GetTracksByAlbum(message.Album.Id);
tracks.ForEach(x => x.TrackFileId = 0);
_trackService.SetFileIds(tracks);
_commandQueueManager.Push(new RescanArtistCommand(message.Album.ArtistId, FilterFilesType.Matched));
} }
} }
} }

Loading…
Cancel
Save