diff --git a/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs index 0020bb24f..d20f906c6 100644 --- a/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs @@ -73,23 +73,37 @@ namespace Ombi.Schedule.Jobs.Radarr private async Task ProcessMovies() { var availableRadarrMovies = _radarrRepo.GetAll().Where(x => x.HasFile).ToImmutableHashSet(); - var unavailableMovieRequests = _movies.GetAll().Where(x => !x.Available).ToImmutableHashSet(); + var unavailableMovieRequests = _movies.GetAll().Where(x => !x.Available || (!x.Available4K && x.Has4KRequest)).ToImmutableHashSet(); var itemsForAvailability = new List(); foreach (var movieRequest in unavailableMovieRequests) { // Do we have an item in the radarr list - var available = availableRadarrMovies.Any(x => x.TheMovieDbId == movieRequest.TheMovieDbId); - if (available) + var available = availableRadarrMovies.FirstOrDefault(x => x.TheMovieDbId == movieRequest.TheMovieDbId); + if (available != null) { _logger.LogInformation($"Found move '{movieRequest.Title}' available in Radarr"); - movieRequest.Available = true; - movieRequest.MarkedAsAvailable = DateTime.UtcNow; - itemsForAvailability.Add(new AvailabilityModel + if (available.Has4K && !movieRequest.Available4K) { - Id = movieRequest.Id, - RequestedUser = movieRequest.RequestedUser != null ? movieRequest.RequestedUser.Email : string.Empty - }); + itemsForAvailability.Add(new AvailabilityModel + { + Id = movieRequest.Id, + RequestedUser = movieRequest.RequestedUser != null ? movieRequest.RequestedUser.Email : string.Empty + }); + movieRequest.Available4K = true; + movieRequest.MarkedAsAvailable4K = DateTime.UtcNow; + } + if (available.HasRegular) + { + itemsForAvailability.Add(new AvailabilityModel + { + Id = movieRequest.Id, + RequestedUser = movieRequest.RequestedUser != null ? movieRequest.RequestedUser.Email : string.Empty + }); + movieRequest.Available = true; + movieRequest.MarkedAsAvailable = DateTime.UtcNow; + } + await _movies.SaveChangesAsync(); } } @@ -97,7 +111,6 @@ namespace Ombi.Schedule.Jobs.Radarr { await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) .SendAsync(NotificationHub.NotificationEvent, "Radarr Availability Checker found some new available movies!"); - await _movies.SaveChangesAsync(); } foreach (var item in itemsForAvailability) { @@ -110,7 +123,6 @@ namespace Ombi.Schedule.Jobs.Radarr Recipient = item.RequestedUser }); } - } public async Task ProcessTvShows() diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index a6e1b205b..d8dc273d2 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -211,6 +211,7 @@ namespace Ombi.Schedule.Jobs.Plex movie.Available4K = true; movie.Approved4K = true; movie.MarkedAsAvailable4K = DateTime.Now; + await _movieRepo.SaveChangesAsync(); } // If we have a non-4k versison then mark as available @@ -219,6 +220,7 @@ namespace Ombi.Schedule.Jobs.Plex movie.Available = true; movie.Approved = true; movie.MarkedAsAvailable = DateTime.Now; + await _movieRepo.SaveChangesAsync(); } itemsForAvailbility.Add(new AvailabilityModel @@ -228,11 +230,6 @@ namespace Ombi.Schedule.Jobs.Plex }); } - if (itemsForAvailbility.Any()) - { - await _movieRepo.SaveChangesAsync(); - } - foreach (var i in itemsForAvailbility.DistinctBy(x => x.Id)) { await _notificationService.Notify(new NotificationOptions diff --git a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs index eb97edeff..94970305a 100644 --- a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs @@ -103,10 +103,8 @@ namespace Ombi.Schedule.Jobs.Radarr } } } - // Save from the updates made to the existing movies (they are in the EF Change Tracker) await _radarrRepo.SaveChangesAsync(); - await _radarrRepo.AddRange(movieIds); }