mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
refactor(discover): Move movie trending feature toggle to backend
This commit is contained in:
parent
03d94220c7
commit
70a6a8f953
7 changed files with 13 additions and 53 deletions
|
@ -17,7 +17,6 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies();
|
||||
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies();
|
||||
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad);
|
||||
Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad);
|
||||
Task<MovieCollectionsViewModel> GetCollection(int collectionId, CancellationToken cancellationToken, string langCode = null);
|
||||
Task<int> GetTvDbId(int theMovieDbId);
|
||||
Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null);
|
||||
|
|
|
@ -11,6 +11,7 @@ using Ombi.Core.Models.Search;
|
|||
using Ombi.Core.Models.Search.V2;
|
||||
using Ombi.Core.Models.UI;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Core.Services;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Settings.Settings.Models;
|
||||
|
@ -31,7 +32,8 @@ namespace Ombi.Core.Engine.V2
|
|||
{
|
||||
public MovieSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
ILogger<MovieSearchEngineV2> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub,
|
||||
ISettingsService<CustomizationSettings> customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory)
|
||||
ISettingsService<CustomizationSettings> customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory,
|
||||
IFeatureService feature)
|
||||
: base(identity, service, r, um, mem, s, sub)
|
||||
{
|
||||
MovieApi = movApi;
|
||||
|
@ -40,6 +42,7 @@ namespace Ombi.Core.Engine.V2
|
|||
_customizationSettings = customizationSettings;
|
||||
_movieRequestEngine = movieRequestEngine;
|
||||
_client = httpClientFactory.CreateClient();
|
||||
_feature = feature;
|
||||
}
|
||||
|
||||
private IMovieDbApi MovieApi { get; }
|
||||
|
@ -48,6 +51,7 @@ namespace Ombi.Core.Engine.V2
|
|||
private readonly ISettingsService<CustomizationSettings> _customizationSettings;
|
||||
private readonly IMovieRequestEngine _movieRequestEngine;
|
||||
private readonly HttpClient _client;
|
||||
private readonly IFeatureService _feature;
|
||||
|
||||
public async Task<MovieFullInfoViewModel> GetFullMovieInformation(int theMovieDbId, CancellationToken cancellationToken, string langCode = null)
|
||||
{
|
||||
|
@ -196,30 +200,19 @@ namespace Ombi.Core.Engine.V2
|
|||
public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad)
|
||||
{
|
||||
var langCode = await DefaultLanguageCode(null);
|
||||
var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource);
|
||||
|
||||
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
|
||||
|
||||
var results = new List<MovieDbSearchResult>();
|
||||
foreach (var pagesToLoad in pages)
|
||||
{
|
||||
var search = () => (isNewTrendingSourceEnabled) ?
|
||||
MovieApi.TrendingMovies(langCode, pagesToLoad.Page)
|
||||
: MovieApi.NowPlaying(langCode, pagesToLoad.Page);
|
||||
|
||||
var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode,
|
||||
() => MovieApi.NowPlaying(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12));
|
||||
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
|
||||
}
|
||||
return await TransformMovieResultsToResponse(results);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad)
|
||||
{
|
||||
var langCode = await DefaultLanguageCode(null);
|
||||
|
||||
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
|
||||
|
||||
var results = new List<MovieDbSearchResult>();
|
||||
foreach (var pagesToLoad in pages)
|
||||
{
|
||||
var apiResult = await Cache.GetOrAddAsync(nameof(TrendingMovies) + pagesToLoad.Page + langCode,
|
||||
() => MovieApi.TrendingMovies(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12));
|
||||
search, DateTimeOffset.Now.AddHours(12));
|
||||
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
|
||||
}
|
||||
return await TransformMovieResultsToResponse(results);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue