Fixed: Collections Improvements

Fixes #7383
This commit is contained in:
Qstick 2022-06-25 15:23:39 -05:00
parent 2d68716376
commit fd22cb44f6
6 changed files with 49 additions and 36 deletions

View File

@ -258,23 +258,16 @@ export const actionHandlers = handleThunks({
} = payload;
const response = {};
const collections = [];
collectionIds.forEach((id) => {
const collectionToUpdate = { id };
if (payload.hasOwnProperty('monitored')) {
collectionToUpdate.monitored = monitored;
}
collections.push(collectionToUpdate);
});
if (payload.hasOwnProperty('monitored')) {
response.monitored = monitored;
}
if (payload.hasOwnProperty('monitor')) {
response.monitorMovies = monitor === 'monitored';
}
response.collections = collections;
response.collectionIds = collectionIds;
dispatch(set({
section,

View File

@ -2,13 +2,15 @@ using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Localization;
using NzbDrone.Core.Movies.Collections;
using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(CollectionEditedEvent), CheckOnCondition.Always)]
[CheckOn(typeof(ModelEvent<RootFolder>))]
public class MovieCollectionRootFolderCheck : HealthCheckBase
{
private readonly IMovieCollectionService _collectionService;

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies.Events;
@ -13,6 +14,7 @@ namespace NzbDrone.Core.Movies.Collections
IEnumerable<MovieCollection> GetCollections(IEnumerable<int> ids);
List<MovieCollection> GetAllCollections();
MovieCollection UpdateCollection(MovieCollection collection);
List<MovieCollection> UpdateCollections(List<MovieCollection> collections);
void RemoveCollection(MovieCollection collection);
bool Upsert(MovieCollection collection);
bool UpsertMany(List<MovieCollection> collections);
@ -23,12 +25,14 @@ namespace NzbDrone.Core.Movies.Collections
private readonly IMovieCollectionRepository _repo;
private readonly IMovieService _movieService;
private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
public MovieCollectionService(IMovieCollectionRepository repo, IMovieService movieService, IEventAggregator eventAggregator)
public MovieCollectionService(IMovieCollectionRepository repo, IMovieService movieService, IEventAggregator eventAggregator, Logger logger)
{
_repo = repo;
_movieService = movieService;
_eventAggregator = eventAggregator;
_logger = logger;
}
public MovieCollection AddCollection(MovieCollection newCollection)
@ -73,6 +77,21 @@ namespace NzbDrone.Core.Movies.Collections
return updatedCollection;
}
public List<MovieCollection> UpdateCollections(List<MovieCollection> collections)
{
_logger.Debug("Updating {0} movie collections", collections.Count);
foreach (var c in collections)
{
_logger.Trace("Updating: {0}", c.Title);
}
_repo.UpdateMany(collections);
_logger.Debug("{0} movie collections updated", collections.Count);
return collections;
}
public void RemoveCollection(MovieCollection collection)
{
_repo.Delete(collection);

View File

@ -12,7 +12,7 @@ using NzbDrone.Core.Movies.Events;
namespace NzbDrone.Core.Movies
{
public class RefreshCollectionService : IExecute<RefreshCollectionsCommand>, IHandle<CollectionEditedEvent>
public class RefreshCollectionService : IExecute<RefreshCollectionsCommand>
{
private readonly IProvideMovieInfo _movieInfo;
private readonly IMovieCollectionService _collectionService;
@ -151,10 +151,5 @@ namespace NzbDrone.Core.Movies
}
}
}
public void Handle(CollectionEditedEvent message)
{
SyncCollectionMovies(message.Collection);
}
}
}

View File

@ -2,9 +2,11 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Collections;
using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.Organizer;
using NzbDrone.SignalR;
@ -25,13 +27,15 @@ namespace Radarr.Api.V3.Collections
private readonly IMovieMetadataService _movieMetadataService;
private readonly IBuildFileNames _fileNameBuilder;
private readonly INamingConfigService _namingService;
private readonly IManageCommandQueue _commandQueueManager;
public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
IMovieCollectionService collectionService,
IMovieService movieService,
IMovieMetadataService movieMetadataService,
IBuildFileNames fileNameBuilder,
INamingConfigService namingService)
INamingConfigService namingService,
IManageCommandQueue commandQueueManager)
: base(signalRBroadcaster)
{
_collectionService = collectionService;
@ -39,6 +43,7 @@ namespace Radarr.Api.V3.Collections
_movieMetadataService = movieMetadataService;
_fileNameBuilder = fileNameBuilder;
_namingService = namingService;
_commandQueueManager = commandQueueManager;
}
protected override CollectionResource GetResourceById(int id)
@ -67,34 +72,32 @@ namespace Radarr.Api.V3.Collections
}
[HttpPut]
public ActionResult UpdateCollections(CollectionUpdateResource collectionResources)
public ActionResult UpdateCollections(CollectionUpdateResource resource)
{
var collectionsToUpdate = _collectionService.GetCollections(collectionResources.Collections.Select(c => c.Id));
var update = new List<CollectionResource>();
var collectionsToUpdate = _collectionService.GetCollections(resource.CollectionIds);
foreach (var c in collectionResources.Collections)
foreach (var collection in collectionsToUpdate)
{
var collection = collectionsToUpdate.Single(n => n.Id == c.Id);
if (c.Monitored.HasValue)
if (resource.Monitored.HasValue)
{
collection.Monitored = c.Monitored.Value;
collection.Monitored = resource.Monitored.Value;
}
if (collectionResources.MonitorMovies.HasValue)
if (resource.MonitorMovies.HasValue)
{
var movies = _movieService.GetMoviesByCollectionTmdbId(collection.TmdbId);
movies.ForEach(c => c.Monitored = collectionResources.MonitorMovies.Value);
movies.ForEach(c => c.Monitored = resource.MonitorMovies.Value);
_movieService.UpdateMovie(movies, true);
}
var updatedCollection = _collectionService.UpdateCollection(collection);
update.Add(updatedCollection.ToResource());
}
return Accepted(update);
var updated = _collectionService.UpdateCollections(collectionsToUpdate.ToList()).ToResource();
_commandQueueManager.Push(new RefreshCollectionsCommand());
return Accepted(updated);
}
private IEnumerable<CollectionResource> MapToResource(List<MovieCollection> collections, List<MovieMetadata> collectionMovies)
@ -125,7 +128,7 @@ namespace Radarr.Api.V3.Collections
foreach (var movie in _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId))
{
var movieResource = movie.ToResource();
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { Title = movie.Title, Year = movie.Year, ImdbId = movie.ImdbId, TmdbId = movie.TmdbId });
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie });
resource.Movies.Add(movieResource);
}

View File

@ -5,7 +5,8 @@ namespace Radarr.Api.V3.Collections
{
public class CollectionUpdateResource
{
public List<CollectionUpdateCollectionResource> Collections { get; set; }
public List<int> CollectionIds { get; set; }
public bool? Monitored { get; set; }
public bool? MonitorMovies { get; set; }
}
}