refactor(discover): Move movie trending feature toggle to backend

This commit is contained in:
sephrat 2022-04-26 12:56:02 +02:00
commit 70a6a8f953
7 changed files with 13 additions and 53 deletions

View file

@ -17,7 +17,6 @@ namespace Ombi.Core.Engine.Interfaces
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies(); Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies();
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(); Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies();
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad); 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<MovieCollectionsViewModel> GetCollection(int collectionId, CancellationToken cancellationToken, string langCode = null);
Task<int> GetTvDbId(int theMovieDbId); Task<int> GetTvDbId(int theMovieDbId);
Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null); Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null);

View file

@ -11,6 +11,7 @@ using Ombi.Core.Models.Search;
using Ombi.Core.Models.Search.V2; using Ombi.Core.Models.Search.V2;
using Ombi.Core.Models.UI; using Ombi.Core.Models.UI;
using Ombi.Core.Rule.Interfaces; using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Services;
using Ombi.Core.Settings; using Ombi.Core.Settings;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models;
@ -31,7 +32,8 @@ namespace Ombi.Core.Engine.V2
{ {
public MovieSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper, 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, 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) : base(identity, service, r, um, mem, s, sub)
{ {
MovieApi = movApi; MovieApi = movApi;
@ -40,6 +42,7 @@ namespace Ombi.Core.Engine.V2
_customizationSettings = customizationSettings; _customizationSettings = customizationSettings;
_movieRequestEngine = movieRequestEngine; _movieRequestEngine = movieRequestEngine;
_client = httpClientFactory.CreateClient(); _client = httpClientFactory.CreateClient();
_feature = feature;
} }
private IMovieDbApi MovieApi { get; } private IMovieDbApi MovieApi { get; }
@ -48,6 +51,7 @@ namespace Ombi.Core.Engine.V2
private readonly ISettingsService<CustomizationSettings> _customizationSettings; private readonly ISettingsService<CustomizationSettings> _customizationSettings;
private readonly IMovieRequestEngine _movieRequestEngine; private readonly IMovieRequestEngine _movieRequestEngine;
private readonly HttpClient _client; private readonly HttpClient _client;
private readonly IFeatureService _feature;
public async Task<MovieFullInfoViewModel> GetFullMovieInformation(int theMovieDbId, CancellationToken cancellationToken, string langCode = null) 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) public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad)
{ {
var langCode = await DefaultLanguageCode(null); var langCode = await DefaultLanguageCode(null);
var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource);
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems); var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
var results = new List<MovieDbSearchResult>(); var results = new List<MovieDbSearchResult>();
foreach (var pagesToLoad in pages) 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, var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode,
() => MovieApi.NowPlaying(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);
}
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));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
} }
return await TransformMovieResultsToResponse(results); return await TransformMovieResultsToResponse(results);

View file

@ -38,7 +38,6 @@ export class CarouselListComponent implements OnInit {
public loadingFlag: boolean; public loadingFlag: boolean;
public DiscoverType = DiscoverType; public DiscoverType = DiscoverType;
public is4kEnabled = false; public is4kEnabled = false;
public isNewTrendingSourceEnabled = false;
get mediaTypeStorageKey() { get mediaTypeStorageKey() {
return "DiscoverOptions" + this.discoverType.toString(); return "DiscoverOptions" + this.discoverType.toString();
@ -140,7 +139,6 @@ export class CarouselListComponent implements OnInit {
public async ngOnInit() { public async ngOnInit() {
this.is4kEnabled = this.featureFacade.is4kEnabled(); this.is4kEnabled = this.featureFacade.is4kEnabled();
this.isNewTrendingSourceEnabled = this.featureFacade.isNewTrendingSourceEnabled();
this.currentlyLoaded = 0; this.currentlyLoaded = 0;
const localDiscoverOptions = +this.storageService.get(this.mediaTypeStorageKey); const localDiscoverOptions = +this.storageService.get(this.mediaTypeStorageKey);
if (localDiscoverOptions) { if (localDiscoverOptions) {
@ -226,11 +224,7 @@ export class CarouselListComponent implements OnInit {
this.movies = await this.searchService.popularMoviesByPage(this.currentlyLoaded, this.amountToLoad); this.movies = await this.searchService.popularMoviesByPage(this.currentlyLoaded, this.amountToLoad);
break; break;
case DiscoverType.Trending: case DiscoverType.Trending:
if(this.isNewTrendingSourceEnabled) {
this.movies = await this.searchService.trendingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
} else {
this.movies = await this.searchService.nowPlayingMoviesByPage(this.currentlyLoaded, this.amountToLoad); this.movies = await this.searchService.nowPlayingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
}
break; break;
case DiscoverType.Upcoming: case DiscoverType.Upcoming:
this.movies = await this.searchService.upcomingMoviesByPage(this.currentlyLoaded, this.amountToLoad); this.movies = await this.searchService.upcomingMoviesByPage(this.currentlyLoaded, this.amountToLoad);

View file

@ -91,10 +91,6 @@ export class SearchV2Service extends ServiceHelpers {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise(); return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise();
} }
public trendingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/trending/${currentlyLoaded}/${toLoad}`).toPromise();
}
public topRatedMovies(): Observable<ISearchMovieResult[]> { public topRatedMovies(): Observable<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/toprated`); return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/toprated`);
} }

View file

@ -23,6 +23,4 @@ export class FeaturesFacade {
public is4kEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.is4kEnabled); public is4kEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.is4kEnabled);
public isNewTrendingSourceEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.isNewTrendingSourceEnabled); }
}

View file

@ -15,9 +15,4 @@ export class FeaturesSelectors {
return features.filter(x => x.name === "Movie4KRequests")[0].enabled; return features.filter(x => x.name === "Movie4KRequests")[0].enabled;
} }
@Selector([FeaturesSelectors.features]) }
public static isNewTrendingSourceEnabled(features: IFeatureEnablement[]): boolean {
return features.filter(x => x.name === "NewTrendingSource")[0].enabled;
}
}

View file

@ -285,21 +285,6 @@ namespace Ombi.Controllers.V2
() => _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad), () => _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad),
DateTimeOffset.Now.AddHours(12)); DateTimeOffset.Now.AddHours(12));
} }
/// <summary>
/// Returns trending movies by page
/// </summary>
/// <remarks>We use TheMovieDb as the Provider</remarks>
/// <returns></returns>
[HttpGet("movie/trending/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad)
{
return _mediaCacheService.GetOrAddAsync(nameof(TrendingMovies) + currentPosition + amountToLoad,
() => _movieEngineV2.TrendingMovies(currentPosition, amountToLoad),
DateTimeOffset.Now.AddHours(12));
}
/// <summary> /// <summary>
/// Returns top rated movies. /// Returns top rated movies.