#1513 correctly set the child requests as approved

pull/1529/head
tidusjar 7 years ago
parent 0de8494b9e
commit cd5cc1fe26

@ -1,38 +1,39 @@
using AutoMapper; using System;
using AutoMapper;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models; using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Models.Requests; using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search; using Ombi.Core.Models.Search;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Store.Repository;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ombi.Core.Rule.Interfaces; using Ombi.Core.Rule.Interfaces;
using StackExchange.Profiling; using StackExchange.Profiling;
using Ombi.Store.Entities; using Microsoft.Extensions.Caching.Memory;
using Microsoft.AspNetCore.Identity; using Ombi.Api.Trakt;
using Ombi.Core.Authentication; using Ombi.Core.Authentication;
using Ombi.Helpers;
namespace Ombi.Core.Engine namespace Ombi.Core.Engine
{ {
public class MovieSearchEngine : BaseMediaEngine, IMovieEngine public class MovieSearchEngine : BaseMediaEngine, IMovieEngine
{ {
public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper, public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
ILogger<MovieSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um) ILogger<MovieSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um, IMemoryCache mem)
: base(identity, service, r, um) : base(identity, service, r, um)
{ {
MovieApi = movApi; MovieApi = movApi;
Mapper = mapper; Mapper = mapper;
Logger = logger; Logger = logger;
MemCache = mem;
} }
private IMovieDbApi MovieApi { get; } private IMovieDbApi MovieApi { get; }
private IMapper Mapper { get; } private IMapper Mapper { get; }
private ILogger<MovieSearchEngine> Logger { get; } private ILogger<MovieSearchEngine> Logger { get; }
private IMemoryCache MemCache { get; }
/// <summary> /// <summary>
/// Lookups the imdb information. /// Lookups the imdb information.
@ -78,7 +79,11 @@ namespace Ombi.Core.Engine
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SearchMovieViewModel>> PopularMovies() public async Task<IEnumerable<SearchMovieViewModel>> PopularMovies()
{ {
var result = await MovieApi.PopularMovies(); var result = await MemCache.GetOrCreateAsync(CacheKeys.PopularMovies, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await MovieApi.PopularMovies();
});
if (result != null) if (result != null)
{ {
Logger.LogDebug("Search Result: {result}", result); Logger.LogDebug("Search Result: {result}", result);
@ -93,7 +98,11 @@ namespace Ombi.Core.Engine
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies() public async Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies()
{ {
var result = await MovieApi.TopRated(); var result = await MemCache.GetOrCreateAsync(CacheKeys.TopRatedMovies, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await MovieApi.TopRated();
});
if (result != null) if (result != null)
{ {
Logger.LogDebug("Search Result: {result}", result); Logger.LogDebug("Search Result: {result}", result);
@ -108,7 +117,11 @@ namespace Ombi.Core.Engine
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies() public async Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies()
{ {
var result = await MovieApi.Upcoming(); var result = await MemCache.GetOrCreateAsync(CacheKeys.UpcomingMovies, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await MovieApi.Upcoming();
});
if (result != null) if (result != null)
{ {
Logger.LogDebug("Search Result: {result}", result); Logger.LogDebug("Search Result: {result}", result);
@ -123,7 +136,11 @@ namespace Ombi.Core.Engine
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies() public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies()
{ {
var result = await MovieApi.NowPlaying(); var result = await MemCache.GetOrCreateAsync(CacheKeys.NowPlayingMovies, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await MovieApi.NowPlaying();
});
if (result != null) if (result != null)
{ {
Logger.LogDebug("Search Result: {result}", result); Logger.LogDebug("Search Result: {result}", result);

@ -20,14 +20,17 @@ using Ombi.Store.Repository.Requests;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Ombi.Core.Authentication; using Ombi.Core.Authentication;
using Ombi.Helpers;
namespace Ombi.Core.Engine namespace Ombi.Core.Engine
{ {
public class TvSearchEngine : BaseMediaEngine, ITvSearchEngine public class TvSearchEngine : BaseMediaEngine, ITvSearchEngine
{ {
public TvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper, ISettingsService<PlexSettings> plexSettings, public TvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper, ISettingsService<PlexSettings> plexSettings,
ISettingsService<EmbySettings> embySettings, IPlexContentRepository repo, IEmbyContentRepository embyRepo, ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um) ISettingsService<EmbySettings> embySettings, IPlexContentRepository repo, IEmbyContentRepository embyRepo, ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um,
IMemoryCache memCache)
: base(identity, service, r, um) : base(identity, service, r, um)
{ {
TvMazeApi = tvMaze; TvMazeApi = tvMaze;
@ -37,6 +40,7 @@ namespace Ombi.Core.Engine
PlexContentRepo = repo; PlexContentRepo = repo;
TraktApi = trakt; TraktApi = trakt;
EmbyContentRepo = embyRepo; EmbyContentRepo = embyRepo;
MemCache = memCache;
} }
private ITvMazeApi TvMazeApi { get; } private ITvMazeApi TvMazeApi { get; }
@ -46,6 +50,7 @@ namespace Ombi.Core.Engine
private IPlexContentRepository PlexContentRepo { get; } private IPlexContentRepository PlexContentRepo { get; }
private IEmbyContentRepository EmbyContentRepo { get; } private IEmbyContentRepository EmbyContentRepo { get; }
private ITraktApi TraktApi { get; } private ITraktApi TraktApi { get; }
private IMemoryCache MemCache { get; }
public async Task<IEnumerable<SearchTvShowViewModel>> Search(string searchTerm) public async Task<IEnumerable<SearchTvShowViewModel>> Search(string searchTerm)
{ {
@ -127,28 +132,44 @@ namespace Ombi.Core.Engine
public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Popular() public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Popular()
{ {
var result = await TraktApi.GetPopularShows(); var result = await MemCache.GetOrCreateAsync(CacheKeys.PopularTv, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await TraktApi.GetPopularShows();
});
var processed = await ProcessResults(result); var processed = await ProcessResults(result);
return processed.Select(ParseIntoTreeNode).ToList(); return processed.Select(ParseIntoTreeNode).ToList();
} }
public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Anticipated() public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Anticipated()
{ {
var result = await TraktApi.GetAnticipatedShows(); var result = await MemCache.GetOrCreateAsync(CacheKeys.AnticipatedTv, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await TraktApi.GetAnticipatedShows();
});
var processed= await ProcessResults(result); var processed= await ProcessResults(result);
return processed.Select(ParseIntoTreeNode).ToList(); return processed.Select(ParseIntoTreeNode).ToList();
} }
public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> MostWatches() public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> MostWatches()
{ {
var result = await TraktApi.GetMostWatchesShows(); var result = await MemCache.GetOrCreateAsync(CacheKeys.MostWatchesTv, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await TraktApi.GetMostWatchesShows();
});
var processed = await ProcessResults(result); var processed = await ProcessResults(result);
return processed.Select(ParseIntoTreeNode).ToList(); return processed.Select(ParseIntoTreeNode).ToList();
} }
public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Trending() public async Task<IEnumerable<TreeNode<SearchTvShowViewModel>>> Trending()
{ {
var result = await TraktApi.GetTrendingShows(); var result = await MemCache.GetOrCreateAsync(CacheKeys.TrendingTv, async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
return await TraktApi.GetTrendingShows();
});
var processed = await ProcessResults(result); var processed = await ProcessResults(result);
return processed.Select(ParseIntoTreeNode).ToList(); return processed.Select(ParseIntoTreeNode).ToList();
} }

@ -8,5 +8,13 @@ namespace Ombi.Helpers
{ {
public const string Update = nameof(Update); public const string Update = nameof(Update);
public const string OmbiSettings = nameof(OmbiSettings); public const string OmbiSettings = nameof(OmbiSettings);
public const string PopularTv = nameof(PopularTv);
public const string AnticipatedTv = nameof(AnticipatedTv);
public const string MostWatchesTv = nameof(MostWatchesTv);
public const string TrendingTv = nameof(TrendingTv);
public const string PopularMovies = nameof(PopularMovies);
public const string TopRatedMovies = nameof(TopRatedMovies);
public const string UpcomingMovies = nameof(UpcomingMovies);
public const string NowPlayingMovies = nameof(NowPlayingMovies);
} }
} }

@ -91,15 +91,15 @@ namespace Ombi.Store.Repository.Requests
public async Task Update(TvRequests request) public async Task Update(TvRequests request)
{ {
Db.Attach(request).State = EntityState.Modified; Db.Update(request);
await Db.SaveChangesAsync(); await Db.SaveChangesAsync();
} }
public async Task UpdateChild(ChildRequests request) public async Task UpdateChild(ChildRequests request)
{ {
Db.Attach(request).State = EntityState.Modified; Db.Update(request);
await Db.SaveChangesAsync(); await Db.SaveChangesAsync();
} }
} }

Loading…
Cancel
Save