diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 456ba267a..51a1c14db 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -188,11 +188,7 @@ namespace Ombi.Core.Engine var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count) .ToListAsync(); - requests.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, requests); return new RequestsViewModel { Collection = requests, @@ -251,26 +247,30 @@ namespace Ombi.Core.Engine allRequests = await MovieRepository.GetWithUser().ToListAsync(); } - allRequests.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, allRequests); + return allRequests; } - private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List movieRequests) { - if (shouldHide.UserId == x.RequestedUserId) + var requestIds = movieRequests.Select(x => x.Id); + var sub = await _subscriptionRepository.GetAll().Where(s => + s.UserId == shouldHide.UserId && requestIds.Contains(s.RequestId) && s.RequestType == RequestType.Movie) + .ToListAsync(); + foreach (var x in movieRequests) { - x.ShowSubscribe = false; - } - else - { - x.ShowSubscribe = true; - var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => - s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie); - x.Subscribed = sub != null; + x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var hasSub = sub.FirstOrDefault(r => r.RequestId == x.Id); + x.Subscribed = hasSub != null; + } } } @@ -293,11 +293,8 @@ namespace Ombi.Core.Engine } var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList(); - results.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, results); + return results; } @@ -493,7 +490,7 @@ namespace Ombi.Core.Engine RequestType = RequestType.Movie, }); - return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id}; + return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id }; } public async Task GetRemainingRequests(OmbiUser user) @@ -533,7 +530,7 @@ namespace Ombi.Core.Engine return new RequestQuotaCountModel() { - HasLimit = true, + HasLimit = true, Limit = limit, Remaining = count, NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc), diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 796e2fe6a..28ab90a89 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -156,10 +156,10 @@ namespace Ombi.Core.Engine .ThenInclude(x => x.Episodes) .OrderByDescending(x => x.ChildRequests.Select(y => y.RequestedDate).FirstOrDefault()) .Skip(position).Take(count).ToListAsync(); - - } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + } + await CheckForSubscription(shouldHide, allRequests); + allRequests.ForEach(async r => { }); return new RequestsViewModel { @@ -194,7 +194,8 @@ namespace Ombi.Core.Engine { return new RequestsViewModel(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + + await CheckForSubscription(shouldHide, allRequests); return new RequestsViewModel { @@ -216,7 +217,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.Get().ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -236,7 +237,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.GetLite().ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -255,7 +256,7 @@ namespace Ombi.Core.Engine request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync(); } - await CheckForSubscription(shouldHide, request); + await CheckForSubscription(shouldHide, new List{request}); return request; } @@ -304,7 +305,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.GetChild().Include(x => x.SeasonRequests).Where(x => x.ParentRequestId == tvId).ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -323,7 +324,7 @@ namespace Ombi.Core.Engine } var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); - results.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, results); return results; } @@ -420,7 +421,7 @@ namespace Ombi.Core.Engine public async Task UpdateChildRequest(ChildRequests request) { - await TvRepository.UpdateChild(request); + await TvRepository.UpdateChild(request); return request; } @@ -438,14 +439,14 @@ namespace Ombi.Core.Engine // Delete the parent TvRepository.Db.TvRequests.Remove(parent); } - + await TvRepository.Db.SaveChangesAsync(); } public async Task RemoveTvRequest(int requestId) { var request = await TvRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId); - await TvRepository.Delete(request); + await TvRepository.Delete(request); } public async Task UserHasRequest(string userId) @@ -520,26 +521,32 @@ namespace Ombi.Core.Engine } } - private async Task CheckForSubscription(HideResult shouldHide, TvRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List x) { - foreach (var tv in x.ChildRequests) + foreach (var tvRequest in x) { - await CheckForSubscription(shouldHide, tv); + await CheckForSubscription(shouldHide, tvRequest.ChildRequests); } } - private async Task CheckForSubscription(HideResult shouldHide, ChildRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List childRequests) { - if (shouldHide.UserId == x.RequestedUserId) + var sub = _subscriptionRepository.GetAll(); + var childIds = childRequests.Select(x => x.Id); + var relevantSubs = await sub.Where(s => + s.UserId == shouldHide.UserId && childIds.Contains(s.Id) && s.RequestType == RequestType.TvShow).ToListAsync(); + foreach (var x in childRequests) { - x.ShowSubscribe = false; - } - else - { - x.ShowSubscribe = true; - var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => - s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.TvShow); - x.Subscribed = sub != null; + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var result = relevantSubs.FirstOrDefault(s => s.RequestId == x.Id); + x.Subscribed = result != null; + } } } @@ -560,7 +567,7 @@ namespace Ombi.Core.Engine return await AfterRequest(model.ChildRequests.FirstOrDefault()); } - private static List SortEpisodes(List items) + private static List SortEpisodes(List items) { foreach (var value in items) { @@ -597,7 +604,7 @@ namespace Ombi.Core.Engine var result = await TvSender.Send(model); if (result.Success) { - return new RequestEngineResult { Result = true, RequestId = model.Id}; + return new RequestEngineResult { Result = true, RequestId = model.Id }; } return new RequestEngineResult { @@ -650,10 +657,10 @@ namespace Ombi.Core.Engine DateTime oldestRequestedAt = await log.OrderBy(x => x.RequestDate) .Select(x => x.RequestDate) .FirstOrDefaultAsync(); - + return new RequestQuotaCountModel() { - HasLimit = true, + HasLimit = true, Limit = limit, Remaining = count, NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc), diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index 9c92bc509..d713cab80 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -213,7 +213,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { - _movieRepo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 362840203..2d4b168af 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -206,7 +206,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { _settings?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 69ebdc42c..90236aef8 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -156,7 +156,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { _settings?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs index 6a16aad70..e7b7f2633 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs @@ -49,7 +49,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _issuesRepository?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs index cf8cbd831..9c1c8b638 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs @@ -99,7 +99,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plexRepo?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 503410d82..32254f09a 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -66,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly IPlexContentRepository _plex; private readonly IEmbyContentRepository _emby; - private readonly IExternalRepository _recentlyAddedLog; + private readonly IRepository _recentlyAddedLog; private readonly IMovieDbApi _movieApi; private readonly ITvMazeApi _tvApi; private readonly IEmailProvider _email; @@ -78,7 +78,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly UserManager _userManager; private readonly ILogger _log; private readonly ILidarrApi _lidarrApi; - private readonly IRepository _lidarrAlbumRepository; + private readonly IExternalRepository _lidarrAlbumRepository; private readonly ISettingsService _lidarrSettings; private readonly ISettingsService _plexSettings; private readonly ISettingsService _embySettings; @@ -931,12 +931,9 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plex?.Dispose(); - _emby?.Dispose(); _newsletterSettings?.Dispose(); _customizationSettings?.Dispose(); _emailSettings.Dispose(); - _recentlyAddedLog.Dispose(); _templateRepo?.Dispose(); _userManager?.Dispose(); } diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index 0ccb736dc..7766119cc 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -352,8 +352,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plexRepo?.Dispose(); - _embyRepo?.Dispose(); _plexSettings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index 72d7f5a2c..a2b1a56cf 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -193,8 +193,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { - _movieRepo?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 70ab6878d..f290f2dc9 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -650,7 +650,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { Plex?.Dispose(); - Repo?.Dispose(); EpisodeSync?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index 7414294be..dcf5ea395 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -206,7 +206,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { - _repo?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs index a0d11f76a..073a0ed1a 100644 --- a/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs +++ b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs @@ -12,5 +12,10 @@ namespace Ombi.Store.Context.MySql Database.Migrate(); } + + public override void Dispose() + { + base.Dispose(); + } } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/BaseRepository.cs b/src/Ombi.Store/Repository/BaseRepository.cs index 41a7eeb31..2df4d3467 100644 --- a/src/Ombi.Store/Repository/BaseRepository.cs +++ b/src/Ombi.Store/Repository/BaseRepository.cs @@ -107,25 +107,25 @@ namespace Ombi.Store.Repository } - private bool _disposed; - // Protected implementation of Dispose pattern. - protected virtual void Dispose(bool disposing) - { - if (_disposed) - return; + //private bool _disposed; + //// Protected implementation of Dispose pattern. + //protected virtual void Dispose(bool disposing) + //{ + // if (_disposed) + // return; - if (disposing) - { - _ctx?.Dispose(); - } + // if (disposing) + // { + // _ctx?.Dispose(); + // } - _disposed = true; - } + // _disposed = true; + //} - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + //public void Dispose() + //{ + // Dispose(true); + // GC.SuppressFinalize(this); + //} } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/IExternalRepository.cs b/src/Ombi.Store/Repository/IExternalRepository.cs index de8b6db67..b22cb5ea8 100644 --- a/src/Ombi.Store/Repository/IExternalRepository.cs +++ b/src/Ombi.Store/Repository/IExternalRepository.cs @@ -9,7 +9,7 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public interface IExternalRepository : IDisposable where T : Entity + public interface IExternalRepository where T : Entity { Task Find(object key); IQueryable GetAll(); diff --git a/src/Ombi.Store/Repository/IRepository.cs b/src/Ombi.Store/Repository/IRepository.cs index 810b586a3..fd7dcc86d 100644 --- a/src/Ombi.Store/Repository/IRepository.cs +++ b/src/Ombi.Store/Repository/IRepository.cs @@ -9,7 +9,7 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public interface IRepository : IDisposable where T : Entity + public interface IRepository where T : Entity { Task Find(object key); IQueryable GetAll();