mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
Fixed: Don't refresh and rescan artist when new album added
Speeds up adding a single album to an existing artist. Should help reduce the number of full rescans being triggered also - an added album was triggering one.
This commit is contained in:
parent
0e78135f91
commit
12d6b5ee9a
9 changed files with 60 additions and 20 deletions
|
@ -54,8 +54,8 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
.Returns((List<Artist> artists, bool doRefresh) => artists);
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Setup(v => v.AddAlbums(It.IsAny<List<Album>>()))
|
||||
.Returns((List<Album> albums) => albums);
|
||||
.Setup(v => v.AddAlbums(It.IsAny<List<Album>>(), false))
|
||||
.Returns((List<Album> albums, bool doRefresh) => albums);
|
||||
}
|
||||
|
||||
private void WithAlbum()
|
||||
|
@ -208,7 +208,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1)));
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1), false));
|
||||
}
|
||||
|
||||
[TestCase(ImportListMonitorType.None, false)]
|
||||
|
@ -236,7 +236,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1 && t.First().Monitored == expectedAlbumMonitored)));
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1 && t.First().Monitored == expectedAlbumMonitored), false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -260,7 +260,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0), false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -273,7 +273,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace NzbDrone.Core.ImportLists
|
|||
}
|
||||
|
||||
var addedArtists = _addArtistService.AddArtists(artistsToAdd, false);
|
||||
var addedAlbums = _addAlbumService.AddAlbums(albumsToAdd);
|
||||
var addedAlbums = _addAlbumService.AddAlbums(albumsToAdd, false);
|
||||
|
||||
var message = string.Format($"Import List Sync Completed. Items found: {reports.Count}, Artists added: {addedArtists.Count}, Albums added: {addedAlbums.Count}");
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace NzbDrone.Core.MediaCover
|
|||
public class MediaCoverService :
|
||||
IHandleAsync<ArtistRefreshCompleteEvent>,
|
||||
IHandleAsync<ArtistDeletedEvent>,
|
||||
IHandleAsync<AlbumAddedEvent>,
|
||||
IHandleAsync<AlbumDeletedEvent>,
|
||||
IMapCoversToLocal
|
||||
{
|
||||
|
@ -292,6 +293,14 @@ namespace NzbDrone.Core.MediaCover
|
|||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(AlbumAddedEvent message)
|
||||
{
|
||||
if (message.DoRefresh)
|
||||
{
|
||||
EnsureAlbumCovers(message.Album);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(AlbumDeletedEvent message)
|
||||
{
|
||||
var path = GetAlbumCoverPath(message.Album.Id);
|
||||
|
|
|
@ -5,14 +5,16 @@ namespace NzbDrone.Core.Music.Commands
|
|||
public class RefreshAlbumCommand : Command
|
||||
{
|
||||
public int? AlbumId { get; set; }
|
||||
public bool IsNewAlbum { get; set; }
|
||||
|
||||
public RefreshAlbumCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public RefreshAlbumCommand(int? albumId)
|
||||
public RefreshAlbumCommand(int? albumId, bool isNewAlbum = false)
|
||||
{
|
||||
AlbumId = albumId;
|
||||
IsNewAlbum = isNewAlbum;
|
||||
}
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
|
|
|
@ -5,10 +5,12 @@ namespace NzbDrone.Core.Music.Events
|
|||
public class AlbumAddedEvent : IEvent
|
||||
{
|
||||
public Album Album { get; private set; }
|
||||
public bool DoRefresh { get; private set; }
|
||||
|
||||
public AlbumAddedEvent(Album album)
|
||||
public AlbumAddedEvent(Album album, bool doRefresh = true)
|
||||
{
|
||||
Album = album;
|
||||
DoRefresh = doRefresh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,31 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
public class AlbumAddedHandler : IHandle<AlbumAddedEvent>
|
||||
{
|
||||
private readonly ICheckIfArtistShouldBeRefreshed _checkIfArtistShouldBeRefreshed;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
|
||||
public AlbumAddedHandler(IManageCommandQueue commandQueueManager)
|
||||
public AlbumAddedHandler(ICheckIfArtistShouldBeRefreshed checkIfArtistShouldBeRefreshed,
|
||||
IManageCommandQueue commandQueueManager)
|
||||
{
|
||||
_checkIfArtistShouldBeRefreshed = checkIfArtistShouldBeRefreshed;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
}
|
||||
|
||||
public void Handle(AlbumAddedEvent message)
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Album.Artist.Value.Id));
|
||||
if (message.DoRefresh)
|
||||
{
|
||||
var artist = message.Album.Artist.Value;
|
||||
|
||||
if (_checkIfArtistShouldBeRefreshed.ShouldRefresh(artist))
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(artist.Id));
|
||||
}
|
||||
else
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshAlbumCommand(message.Album.Id, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
public interface IAddAlbumService
|
||||
{
|
||||
Album AddAlbum(Album album);
|
||||
List<Album> AddAlbums(List<Album> albums);
|
||||
Album AddAlbum(Album album, bool doRefresh = true);
|
||||
List<Album> AddAlbums(List<Album> albums, bool doRefresh = true);
|
||||
}
|
||||
|
||||
public class AddAlbumService : IAddAlbumService
|
||||
|
@ -40,7 +40,7 @@ namespace NzbDrone.Core.Music
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public Album AddAlbum(Album album)
|
||||
public Album AddAlbum(Album album, bool doRefresh = true)
|
||||
{
|
||||
_logger.Debug($"Adding album {album}");
|
||||
|
||||
|
@ -65,12 +65,13 @@ namespace NzbDrone.Core.Music
|
|||
}
|
||||
|
||||
album.ArtistMetadataId = dbArtist.ArtistMetadataId;
|
||||
_albumService.AddAlbum(album);
|
||||
album.Artist = dbArtist;
|
||||
_albumService.AddAlbum(album, doRefresh);
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
public List<Album> AddAlbums(List<Album> albums)
|
||||
public List<Album> AddAlbums(List<Album> albums, bool doRefresh = true)
|
||||
{
|
||||
var added = DateTime.UtcNow;
|
||||
var addedAlbums = new List<Album>();
|
||||
|
@ -78,7 +79,7 @@ namespace NzbDrone.Core.Music
|
|||
foreach (var a in albums)
|
||||
{
|
||||
a.Added = added;
|
||||
addedAlbums.Add(AddAlbum(a));
|
||||
addedAlbums.Add(AddAlbum(a, doRefresh));
|
||||
}
|
||||
|
||||
return addedAlbums;
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace NzbDrone.Core.Music
|
|||
List<Album> GetLastAlbumsByArtistMetadataId(IEnumerable<int> artistMetadataIds);
|
||||
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
|
||||
List<Album> GetAlbumsForRefresh(int artistMetadataId, IEnumerable<string> foreignIds);
|
||||
Album AddAlbum(Album newAlbum);
|
||||
Album AddAlbum(Album newAlbum, bool doRefresh);
|
||||
Album FindById(string foreignId);
|
||||
Album FindByTitle(int artistMetadataId, string title);
|
||||
Album FindByTitleInexact(int artistMetadataId, string title);
|
||||
|
@ -57,11 +57,11 @@ namespace NzbDrone.Core.Music
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public Album AddAlbum(Album newAlbum)
|
||||
public Album AddAlbum(Album newAlbum, bool doRefresh)
|
||||
{
|
||||
_albumRepository.Insert(newAlbum);
|
||||
|
||||
_eventAggregator.PublishEvent(new AlbumAddedEvent(GetAlbum(newAlbum.Id)));
|
||||
_eventAggregator.PublishEvent(new AlbumAddedEvent(GetAlbum(newAlbum.Id), doRefresh));
|
||||
|
||||
return newAlbum;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using NzbDrone.Core.Exceptions;
|
|||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
|
@ -33,6 +34,7 @@ namespace NzbDrone.Core.Music
|
|||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IHistoryService _historyService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private readonly ICheckIfAlbumShouldBeRefreshed _checkIfAlbumShouldBeRefreshed;
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
private readonly Logger _logger;
|
||||
|
@ -47,6 +49,7 @@ namespace NzbDrone.Core.Music
|
|||
IMediaFileService mediaFileService,
|
||||
IHistoryService historyService,
|
||||
IEventAggregator eventAggregator,
|
||||
IManageCommandQueue commandQueueManager,
|
||||
ICheckIfAlbumShouldBeRefreshed checkIfAlbumShouldBeRefreshed,
|
||||
IMapCoversToLocal mediaCoverService,
|
||||
Logger logger)
|
||||
|
@ -61,6 +64,7 @@ namespace NzbDrone.Core.Music
|
|||
_mediaFileService = mediaFileService;
|
||||
_historyService = historyService;
|
||||
_eventAggregator = eventAggregator;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_checkIfAlbumShouldBeRefreshed = checkIfAlbumShouldBeRefreshed;
|
||||
_mediaCoverService = mediaCoverService;
|
||||
_logger = logger;
|
||||
|
@ -359,6 +363,13 @@ namespace NzbDrone.Core.Music
|
|||
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(artist));
|
||||
_eventAggregator.PublishEvent(new AlbumUpdatedEvent(album));
|
||||
}
|
||||
|
||||
if (message.IsNewAlbum)
|
||||
{
|
||||
// Just scan the artist path - triggering a full rescan is too painful
|
||||
var folders = new List<string> { artist.Path };
|
||||
_commandQueueManager.Push(new RescanFoldersCommand(folders, FilterFilesType.Matched, false, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue