From a7ccb74ad9ad14295d3c72e8a35a2bede36001b2 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Thu, 21 Jun 2018 14:13:15 +0100 Subject: [PATCH 1/7] Added a smaller and simplier way of getting TV Request info --- .../Engine/Interfaces/ITvRequestEngine.cs | 2 + src/Ombi.Core/Engine/TvRequestEngine.cs | 64 +++++++++++++++++-- .../PlexAvailabilityCheckerTests.cs | 2 +- .../Requests/ITvRequestRepository.cs | 2 + .../Requests/TvRequestRepository.cs | 18 ++++++ src/Ombi/Controllers/RequestController.cs | 21 ++++++ src/Ombi/appsettings.json | 1 - 7 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 28eb066d4..064ddf6c9 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -10,6 +10,7 @@ namespace Ombi.Core.Engine.Interfaces { Task RemoveTvRequest(int requestId); + Task GetTvRequest(int requestId); Task RequestTvShow(TvRequestViewModel tv); Task DenyChildRequest(int requestId); Task> SearchTvRequest(string search); @@ -20,5 +21,6 @@ namespace Ombi.Core.Engine.Interfaces Task UpdateChildRequest(ChildRequests request); Task RemoveTvChild(int requestId); Task ApproveChildRequest(int id); + Task> GetRequestsLite(); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 1667873ea..6dfd5b7f3 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -218,6 +218,45 @@ namespace Ombi.Core.Engine return allRequests; } + + public async Task> GetRequestsLite() + { + var shouldHide = await HideFromOtherUsers(); + List allRequests; + if (shouldHide.Hide) + { + allRequests = await TvRepository.GetLite(shouldHide.UserId).ToListAsync(); + + FilterChildren(allRequests, shouldHide); + } + else + { + allRequests = await TvRepository.GetLite().ToListAsync(); + } + + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + return allRequests; + } + + public async Task GetTvRequest(int requestId) + { + var shouldHide = await HideFromOtherUsers(); + TvRequests request; + if (shouldHide.Hide) + { + request = await TvRepository.Get(shouldHide.UserId).Where(x => x.Id == requestId).FirstOrDefaultAsync(); + + FilterChildren(request, shouldHide); + } + else + { + request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync(); + } + + await CheckForSubscription(shouldHide, request); + return request; + } + private static void FilterChildren(IEnumerable allRequests, HideResult shouldHide) { // Filter out children @@ -225,16 +264,27 @@ namespace Ombi.Core.Engine { for (var j = 0; j < t.ChildRequests.Count; j++) { - var child = t.ChildRequests[j]; - if (child.RequestedUserId != shouldHide.UserId) - { - t.ChildRequests.RemoveAt(j); - j--; - } + FilterChildren(t, shouldHide); } } } + private static void FilterChildren(TvRequests t, HideResult shouldHide) + { + // Filter out children + + for (var j = 0; j < t.ChildRequests.Count; j++) + { + var child = t.ChildRequests[j]; + if (child.RequestedUserId != shouldHide.UserId) + { + t.ChildRequests.RemoveAt(j); + j--; + } + } + + } + public async Task> GetAllChldren(int tvId) { var shouldHide = await HideFromOtherUsers(); @@ -470,7 +520,7 @@ namespace Ombi.Core.Engine { foreach (var tv in x.ChildRequests) { - await CheckForSubscription(shouldHide, tv); + await CheckForSubscription(shouldHide, tv); } } diff --git a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs index 0ebb4732c..55c9dc288 100644 --- a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs +++ b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs @@ -26,7 +26,7 @@ namespace Ombi.Schedule.Tests _tv = new Mock(); _movie = new Mock(); _notify = new Mock(); - Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock().Object); + Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock().Object, null); } diff --git a/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs b/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs index 749b67c73..f08f7812f 100644 --- a/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs @@ -14,7 +14,9 @@ namespace Ombi.Store.Repository.Requests Task Delete(TvRequests request); Task DeleteChild(ChildRequests request); IQueryable Get(); + IQueryable GetLite(); IQueryable Get(string userId); + IQueryable GetLite(string userId); Task GetRequestAsync(int tvDbId); TvRequests GetRequest(int tvDbId); Task Update(TvRequests request); diff --git a/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs b/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs index 28a141908..daac7d4df 100644 --- a/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs @@ -60,6 +60,24 @@ namespace Ombi.Store.Repository.Requests .Where(x => x.ChildRequests.Any(a => a.RequestedUserId == userId)) .AsQueryable(); } + + public IQueryable GetLite(string userId) + { + return Db.TvRequests + .Include(x => x.ChildRequests) + .ThenInclude(x => x.RequestedUser) + .Where(x => x.ChildRequests.Any(a => a.RequestedUserId == userId)) + .AsQueryable(); + } + + public IQueryable GetLite() + { + return Db.TvRequests + .Include(x => x.ChildRequests) + .ThenInclude(x => x.RequestedUser) + .AsQueryable(); + } + public IQueryable GetChild() { return Db.ChildRequests diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 47329a0ec..95ea4c09e 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -204,6 +204,27 @@ namespace Ombi.Controllers return await TvRequestEngine.GetRequests(); } + /// + /// Gets the tv requests without the whole object graph (Does not include seasons/episodes). + /// + /// + [HttpGet("tvlite")] + public async Task> GetTvRequestsLite() + { + return await TvRequestEngine.GetRequestsLite(); + } + + /// + /// Returns the full request object for the specified requestId + /// + /// + /// + [HttpGet("tv/{requestId:int}")] + public async Task GetTvRequest(int requestId) + { + return await TvRequestEngine.GetTvRequest(requestId); + } + /// /// Requests a tv show/episode/season. /// diff --git a/src/Ombi/appsettings.json b/src/Ombi/appsettings.json index ed9a1b88a..9505f62a2 100644 --- a/src/Ombi/appsettings.json +++ b/src/Ombi/appsettings.json @@ -10,7 +10,6 @@ }, "ApplicationSettings": { "Verison": "{{VERSIONNUMBER}}", - "OmbiService": "https://ombiservice.azurewebsites.net/", "Branch": "{{BRANCH}}", "FriendlyVersion": "v3.0.0" }, From 6adb0351ea9b3d0837c81952964b3315ffa92429 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 21 Jun 2018 22:33:05 +0100 Subject: [PATCH 2/7] Fixed #2348 --- .../Jobs/Plex/PlexContentSync.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index fec69bcc3..9184755f0 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -104,13 +104,13 @@ namespace Ombi.Schedule.Jobs.Plex BackgroundJob.Enqueue(() => EpisodeSync.Start()); } - if (processedContent.HasProcessedContent && recentlyAddedSearch) + if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) { // Just check what we send it BackgroundJob.Enqueue(() => Metadata.ProcessPlexServerContent(processedContent.Content)); } - if (processedContent.HasProcessedEpisodes && recentlyAddedSearch) + if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch) { BackgroundJob.Enqueue(() => Checker.Start()); } @@ -165,7 +165,7 @@ namespace Ombi.Schedule.Jobs.Plex { Logger.LogInformation("Found some episodes, this must be a recently added sync"); var count = 0; - foreach (var epInfo in content.Metadata) + foreach (var epInfo in content.Metadata ?? new Metadata[]{}) { count++; var grandParentKey = epInfo.grandparentRatingKey; @@ -199,9 +199,11 @@ namespace Ombi.Schedule.Jobs.Plex // Save just to make sure we don't leave anything hanging await Repo.SaveChangesAsync(); - - var episodesAdded = await EpisodeSync.ProcessEpsiodes(content.Metadata, allEps); - episodesProcessed.AddRange(episodesAdded.Select(x => x.Id)); + if (content.Metadata != null) + { + var episodesAdded = await EpisodeSync.ProcessEpsiodes(content.Metadata, allEps); + episodesProcessed.AddRange(episodesAdded.Select(x => x.Id)); + } } if (content.viewGroup.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)) { @@ -350,7 +352,7 @@ namespace Ombi.Schedule.Jobs.Plex } // Do we already have this item? - // Let's try and match + // Let's try and match var existingContent = await Repo.GetFirstContentByCustom(x => x.Title == show.title && x.ReleaseYear == show.year.ToString() && x.Type == PlexMediaTypeEntity.Show); @@ -371,6 +373,10 @@ namespace Ombi.Schedule.Jobs.Plex await Repo.Delete(existingKey); existingKey = null; } + else if(existingContent == null) + { + existingContent = await Repo.GetFirstContentByCustom(x => x.Key == show.ratingKey); + } } if (existingContent != null) From f097dedea663143f0995026da81490d6ef890229 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 22 Jun 2018 23:13:47 +0100 Subject: [PATCH 3/7] Added TVRequestsLite --- .../Engine/Interfaces/ITvRequestEngine.cs | 3 +- src/Ombi.Core/Engine/TvRequestEngine.cs | 29 +++++++++++++++++++ src/Ombi/Controllers/RequestController.cs | 24 +++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 064ddf6c9..348dc91e7 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Ombi.Core.Models.Requests; -using Ombi.Core.Models.Search; +using Ombi.Core.Models.UI; using Ombi.Store.Entities.Requests; namespace Ombi.Core.Engine.Interfaces @@ -13,6 +13,7 @@ namespace Ombi.Core.Engine.Interfaces Task GetTvRequest(int requestId); Task RequestTvShow(TvRequestViewModel tv); Task DenyChildRequest(int requestId); + Task> GetRequestsLite(int count, int position, OrderFilterModel type); Task> SearchTvRequest(string search); Task>>> SearchTvRequestTree(string search); Task UpdateTvRequest(TvRequests request); diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 6dfd5b7f3..e8fc65a26 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -168,6 +168,35 @@ namespace Ombi.Core.Engine }; } + public async Task> GetRequestsLite(int count, int position, OrderFilterModel type) + { + var shouldHide = await HideFromOtherUsers(); + List allRequests; + if (shouldHide.Hide) + { + allRequests = await TvRepository.GetLite(shouldHide.UserId) + .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) + .Skip(position).Take(count).ToListAsync(); + + // Filter out children + + FilterChildren(allRequests, shouldHide); + } + else + { + allRequests = await TvRepository.GetLite() + .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) + .Skip(position).Take(count).ToListAsync(); + } + + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + + return new RequestsViewModel + { + Collection = allRequests + }; + } + public async Task>>> GetRequestsTreeNode(int count, int position) { var shouldHide = await HideFromOtherUsers(); diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 95ea4c09e..483b92280 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -189,8 +189,28 @@ namespace Ombi.Controllers return await TvRequestEngine.GetRequests(count, position, new OrderFilterModel { OrderType = (OrderType)orderType, - AvailabilityFilter = (FilterType) availabilityType, - StatusFilter = (FilterType) statusType, + AvailabilityFilter = (FilterType)availabilityType, + StatusFilter = (FilterType)statusType, + }); + } + + /// + /// Gets the tv requests lite. + /// + /// The count of items you want to return. + /// The position. + /// + /// + /// + /// + [HttpGet("tv/{count:int}/{position:int}/{orderType:int}/{statusFilterType:int}/{availabilityFilterType:int}")] + public async Task> GetTvRequestsLite(int count, int position, int orderType, int statusType, int availabilityType) + { + return await TvRequestEngine.GetRequestsLite(count, position, new OrderFilterModel + { + OrderType = (OrderType)orderType, + AvailabilityFilter = (FilterType)availabilityType, + StatusFilter = (FilterType)statusType, }); } From 54afe5edee61911cf44113dac39ea21d9043cbdb Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 22 Jun 2018 23:38:08 +0100 Subject: [PATCH 4/7] !wip missing thing.... --- src/Ombi/Controllers/RequestController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 483b92280..baeaefcd5 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -203,7 +203,7 @@ namespace Ombi.Controllers /// /// /// - [HttpGet("tv/{count:int}/{position:int}/{orderType:int}/{statusFilterType:int}/{availabilityFilterType:int}")] + [HttpGet("tvlite/{count:int}/{position:int}/{orderType:int}/{statusFilterType:int}/{availabilityFilterType:int}")] public async Task> GetTvRequestsLite(int count, int position, int orderType, int statusType, int availabilityType) { return await TvRequestEngine.GetRequestsLite(count, position, new OrderFilterModel From 7eb6b01e752d6dabec8b18f560677ea8089332b9 Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 23 Jun 2018 00:12:44 +0100 Subject: [PATCH 5/7] Show the popular movies and tv shows by default --- src/Ombi/ClientApp/app/search/moviesearch.component.ts | 1 + src/Ombi/ClientApp/app/search/tvsearch.component.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Ombi/ClientApp/app/search/moviesearch.component.ts b/src/Ombi/ClientApp/app/search/moviesearch.component.ts index ff570441a..236ae8ed8 100644 --- a/src/Ombi/ClientApp/app/search/moviesearch.component.ts +++ b/src/Ombi/ClientApp/app/search/moviesearch.component.ts @@ -70,6 +70,7 @@ export class MovieSearchComponent implements OnInit { result: false, errorMessage: "", }; + this.popularMovies(); } public search(text: any) { diff --git a/src/Ombi/ClientApp/app/search/tvsearch.component.ts b/src/Ombi/ClientApp/app/search/tvsearch.component.ts index 8db75125c..2a456cb6e 100644 --- a/src/Ombi/ClientApp/app/search/tvsearch.component.ts +++ b/src/Ombi/ClientApp/app/search/tvsearch.component.ts @@ -93,6 +93,7 @@ export class TvSearchComponent implements OnInit { result: false, errorMessage:"", }; + this.popularShows(); } public search(text: any) { From b21fc8ea303c5ed5203097c849ca73b0112ed9fa Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 23 Jun 2018 21:10:15 +0100 Subject: [PATCH 6/7] !wip --- src/Ombi/Controllers/SettingsController.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 2e489adf2..2bdb6730a 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -2,19 +2,13 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; using System.Threading.Tasks; using AutoMapper; using Hangfire; -using Hangfire.RecurringJobExtensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.PlatformAbstractions; using NCrontab; using Ombi.Api.Emby; From f222224459b4d849c4d1b42946c1bfa92622732c Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 23 Jun 2018 21:10:55 +0100 Subject: [PATCH 7/7] !wip changelog --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f1e34a8..61d22c16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,21 @@ ### **New Features** +- Added TVRequestsLite. [Jamie] + +- Added a smaller and simplier way of getting TV Request info. [Jamie Rees] + +### **Fixes** + +- Show the popular movies and tv shows by default. [Jamie] + +- Fixed #2348. [Jamie] + + +## v3.0.3407 (2018-06-18) + +### **New Features** + - Update appveyor.yml. [Jamie] - Update build.cake. [Jamie]