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

pull/4624/head
sephrat 2 years ago
parent 03d94220c7
commit 70a6a8f953

@ -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);

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

@ -91,10 +91,6 @@ export class SearchV2Service extends ServiceHelpers {
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[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/toprated`);
}

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

@ -15,9 +15,4 @@ export class FeaturesSelectors {
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;
}
}
}

@ -285,21 +285,6 @@ namespace Ombi.Controllers.V2
() => _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad),
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>
/// Returns top rated movies.

Loading…
Cancel
Save