Added caching all over the new API's this will help with the API limits that we will now easily reach due to the infinate scroll

pull/3895/head
Jamie Rees 6 years ago
parent 9413c7bb48
commit 08abb53923

@ -45,7 +45,9 @@ namespace Ombi.Core.Engine
public async Task<SearchMovieViewModel> LookupImdbInformation(int theMovieDbId, string langCode = null)
{
langCode = await DefaultLanguageCode(langCode);
var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(theMovieDbId, langCode);
var movieInfo = await Cache.GetOrAdd(nameof(LookupImdbInformation) + langCode + theMovieDbId,
async () => await MovieApi.GetMovieInformationWithExtraInfo(theMovieDbId, langCode),
DateTime.Now.AddHours(12));
var viewMovie = Mapper.Map<SearchMovieViewModel>(movieInfo);
return await ProcessSingleMovie(viewMovie, true);

@ -72,13 +72,16 @@ namespace Ombi.Core.Engine
public async Task<SearchTvShowViewModel> GetShowInformation(int tvdbid)
{
var show = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid);
var show = await Cache.GetOrAdd(nameof(GetShowInformation) + tvdbid,
async () => await TvMazeApi.ShowLookupByTheTvDbId(tvdbid), DateTime.Now.AddHours(12));
if (show == null)
{
// We don't have enough information
return null;
}
var episodes = await TvMazeApi.EpisodeLookup(show.id);
var episodes = await Cache.GetOrAdd("TvMazeEpisodeLookup" + show.id,
async () => await TvMazeApi.EpisodeLookup(show.id), DateTime.Now.AddHours(12));
if (episodes == null || !episodes.Any())
{
// We don't have enough information
@ -135,7 +138,8 @@ namespace Ombi.Core.Engine
var results = new List<TraktShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetPopularShows(pagesToLoad.Page, ResultLimit);
var apiResult = await Cache.GetOrAdd(nameof(Popular) + pagesToLoad.Page,
async () => await TraktApi.GetPopularShows(pagesToLoad.Page, ResultLimit), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
@ -155,8 +159,9 @@ namespace Ombi.Core.Engine
var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit);
var results = new List<TraktMostAnticipatedShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetAnticipatedShows(pagesToLoad.Page, ResultLimit);
{
var apiResult = await Cache.GetOrAdd(nameof(Anticipated) + pagesToLoad.Page,
async () => await TraktApi.GetAnticipatedShows(pagesToLoad.Page, ResultLimit), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
@ -183,7 +188,8 @@ namespace Ombi.Core.Engine
var results = new List<TraktMostWatchedShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetMostWatchesShows(null, pagesToLoad.Page, ResultLimit);
var apiResult = await Cache.GetOrAdd(nameof(MostWatches) + pagesToLoad.Page,
async () => await TraktApi.GetMostWatchesShows(null, pagesToLoad.Page, ResultLimit), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
@ -196,7 +202,8 @@ namespace Ombi.Core.Engine
var results = new List<TraktTrendingShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetTrendingShows(pagesToLoad.Page, ResultLimit);
var apiResult = await Cache.GetOrAdd(nameof(Trending) + pagesToLoad.Page,
async () => await TraktApi.GetTrendingShows(pagesToLoad.Page, ResultLimit), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);

@ -41,7 +41,8 @@ namespace Ombi.Core.Engine.V2
public async Task<MovieFullInfoViewModel> GetFullMovieInformation(int theMovieDbId, string langCode = null)
{
langCode = await DefaultLanguageCode(langCode);
var movieInfo = await MovieApi.GetFullMovieInfo(theMovieDbId, langCode);
var movieInfo = await Cache.GetOrAdd(nameof(GetFullMovieInformation) + theMovieDbId + langCode,
async () => await MovieApi.GetFullMovieInfo(theMovieDbId, langCode), DateTime.Now.AddHours(12));
return await ProcessSingleMovie(movieInfo);
}
@ -49,7 +50,8 @@ namespace Ombi.Core.Engine.V2
public async Task<MovieCollectionsViewModel> GetCollection(int collectionId, string langCode = null)
{
langCode = await DefaultLanguageCode(langCode);
var collections = await MovieApi.GetCollection(langCode, collectionId);
var collections = await Cache.GetOrAdd(nameof(GetCollection) + collectionId + langCode,
async () => await MovieApi.GetCollection(langCode, collectionId), DateTime.Now.AddDays(1));
var c = await ProcessCollection(collections);
c.Collection = c.Collection.OrderBy(x => x.ReleaseDate).ToList();
@ -108,13 +110,14 @@ namespace Ombi.Core.Engine.V2
public async Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad)
{
var langCode = await DefaultLanguageCode(null);
var pages = PaginationHelper.GetNextPages(currentlyLoaded, toLoad, _theMovieDbMaxPageItems);
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.PopularMovies(langCode, pagesToLoad.Page);
var apiResult = await Cache.GetOrAdd(nameof(PopularMovies) + pagesToLoad.Page + langCode,
async () => await MovieApi.PopularMovies(langCode, pagesToLoad.Page), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
@ -147,7 +150,8 @@ namespace Ombi.Core.Engine.V2
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.TopRated(langCode, pagesToLoad.Page);
var apiResult = await Cache.GetOrAdd(nameof(TopRatedMovies) + pagesToLoad.Page + langCode,
async () => await MovieApi.TopRated(langCode, pagesToLoad.Page), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
@ -162,7 +166,8 @@ namespace Ombi.Core.Engine.V2
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.NowPlaying(langCode, pagesToLoad.Page);
var apiResult = await Cache.GetOrAdd(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode,
async () => await MovieApi.NowPlaying(langCode, pagesToLoad.Page), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
@ -197,7 +202,8 @@ namespace Ombi.Core.Engine.V2
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.Upcoming(langCode, pagesToLoad.Page);
var apiResult = await Cache.GetOrAdd(nameof(UpcomingMovies) + pagesToLoad.Page + langCode,
async () => await MovieApi.Upcoming(langCode, pagesToLoad.Page), DateTime.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
@ -287,7 +293,8 @@ namespace Ombi.Core.Engine.V2
{
if (viewMovie.ImdbId.IsNullOrEmpty())
{
var showInfo = await MovieApi.GetMovieInformation(viewMovie.Id);
var showInfo = await Cache.GetOrAdd("GetMovieInformationWIthImdbId" + viewMovie.Id,
async () => await MovieApi.GetMovieInformation(viewMovie.Id), DateTime.Now.AddHours(12));
viewMovie.Id = showInfo.Id; // TheMovieDbId
viewMovie.ImdbId = showInfo.ImdbId;
}

@ -1,4 +1,5 @@
using AutoMapper;
using System;
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
@ -50,8 +51,10 @@ namespace Ombi.Core.Engine.V2
public async Task<SearchFullInfoTvShowViewModel> GetShowInformation(int tvdbid)
{
var tvdbshow = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid);
var show = await TvMazeApi.GetTvFullInformation(tvdbshow.id);
var tvdbshow = await Cache.GetOrAdd(nameof(GetShowInformation) + tvdbid,
async () => await TvMazeApi.ShowLookupByTheTvDbId(tvdbid), DateTime.Now.AddHours(12));
var show = await Cache.GetOrAdd("GetTvFullInformation" + tvdbshow.id,
async () => await TvMazeApi.GetTvFullInformation(tvdbshow.id), DateTime.Now.AddHours(12));
if (show == null)
{
// We don't have enough information
@ -62,7 +65,8 @@ namespace Ombi.Core.Engine.V2
Task<TraktShow> traktInfoTask = new Task<TraktShow>(() => null);
if (show.externals?.imdb.HasValue() ?? false)
{
traktInfoTask = TraktApi.GetTvExtendedInfo(show.externals?.imdb);
traktInfoTask = Cache.GetOrAdd("GetExtendedTvInfoTrakt" + show.externals?.imdb,
() => TraktApi.GetTvExtendedInfo(show.externals?.imdb), DateTime.Now.AddHours(12));
}
var mapped = Mapper.Map<SearchFullInfoTvShowViewModel>(show);

@ -1,6 +1,5 @@
// Globals
declare var __webpack_public_path__: any;
declare var module: any;
// declare module "*.json" {
// const value: any;

Loading…
Cancel
Save