From fed4a0aebe4e5488a1695e1a4c58534389a7c42b Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Fri, 14 Dec 2018 09:55:14 +0100 Subject: [PATCH] Fixed: MediaCovers resizing potentially leaking memory when concurrently executing. --- .gitignore | 2 +- .../MediaCover/EnsureMediaCoversCommand.cs | 19 ++++++++++++++ .../MediaCover/MediaCoverService.cs | 25 ++++++++++++++++--- src/NzbDrone.Core/NzbDrone.Core.csproj | 3 ++- 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs diff --git a/.gitignore b/.gitignore index a206d436a..8530d0a58 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,7 @@ _TeamCity* # Radarr Backups/ logs/ -MediaCover/ +#MediaCover/ UpdateLogs/ xdg/ config.xml diff --git a/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs b/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs new file mode 100644 index 000000000..0cb4b02dd --- /dev/null +++ b/src/NzbDrone.Core/MediaCover/EnsureMediaCoversCommand.cs @@ -0,0 +1,19 @@ +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.MediaCover +{ + public class EnsureMediaCoversCommand : Command + { + public int MovieId { get; set; } + + public EnsureMediaCoversCommand() + { + + } + + public EnsureMediaCoversCommand(int movieId) + { + MovieId = movieId; + } + } +} diff --git a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs index 59cd3ba98..13e76e158 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -8,6 +8,7 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Movies; using NzbDrone.Core.Movies.Events; @@ -24,6 +25,7 @@ public class MediaCoverService : IHandleAsync, IHandleAsync, IHandleAsync, + IExecute, IMapCoversToLocal { private readonly IImageResizer _resizer; @@ -32,6 +34,8 @@ public class MediaCoverService : private readonly ICoverExistsSpecification _coverExistsSpecification; private readonly IConfigFileProvider _configFileProvider; private readonly IEventAggregator _eventAggregator; + private readonly IManageCommandQueue _commandQueue; + private readonly IMovieService _movieService; private readonly Logger _logger; private readonly string _coverRootFolder; @@ -43,6 +47,8 @@ public MediaCoverService(IImageResizer resizer, ICoverExistsSpecification coverExistsSpecification, IConfigFileProvider configFileProvider, IEventAggregator eventAggregator, + IManageCommandQueue commandQueue, + IMovieService movieService, Logger logger) { _resizer = resizer; @@ -51,6 +57,8 @@ public MediaCoverService(IImageResizer resizer, _coverExistsSpecification = coverExistsSpecification; _configFileProvider = configFileProvider; _eventAggregator = eventAggregator; + _commandQueue = commandQueue; + _movieService = movieService; _logger = logger; _coverRootFolder = appFolderInfo.GetMediaCoverPath(); @@ -182,16 +190,25 @@ private void EnsureResizedCovers(Movie movie, MediaCover cover, bool forceResize } } + public void Execute(EnsureMediaCoversCommand command) + { + var movie = _movieService.GetMovie(command.MovieId); + EnsureCovers(movie); + _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(movie)); + } + public void HandleAsync(MovieUpdatedEvent message) { - EnsureCovers(message.Movie); - _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); + //EnsureCovers(message.Movie); + _commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id)); + //_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); } public void HandleAsync(MovieAddedEvent message) { - EnsureCovers(message.Movie); - _eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); + //EnsureCovers(message.Movie); + _commandQueue.Push(new EnsureMediaCoversCommand(message.Movie.Id)); + //_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Movie)); } public void HandleAsync(MovieDeletedEvent message) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 691004d60..6a2b87abb 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -152,6 +152,7 @@ + @@ -1326,4 +1327,4 @@ --> - + \ No newline at end of file