Less load on fanart tv if we cache the results for a day

pull/3338/head
tidusjar 5 years ago
parent 4d8f3dfad5
commit 39cef0d54b

@ -38,7 +38,7 @@ namespace Ombi.Controllers.V1
}
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetTvImages(tvdbid, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvdbid}", async () => await FanartTvApi.GetTvImages(tvdbid, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
return string.Empty;
@ -63,7 +63,7 @@ namespace Ombi.Controllers.V1
{
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetMovieImages(movieDbId, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{movieDbId}", async () => await FanartTvApi.GetMovieImages(movieDbId, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
@ -97,7 +97,7 @@ namespace Ombi.Controllers.V1
}
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetTvImages(tvdbid, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvdbid}", async () => await FanartTvApi.GetTvImages(tvdbid, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
@ -127,8 +127,8 @@ namespace Ombi.Controllers.V1
{
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetMovieImages(movieDbId, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{movieDbId}", async () => await FanartTvApi.GetMovieImages(movieDbId, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
return string.Empty;
@ -152,7 +152,7 @@ namespace Ombi.Controllers.V1
{
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetMovieImages(movieDbId, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{movieDbId}", async () => await FanartTvApi.GetMovieImages(movieDbId, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
@ -181,7 +181,7 @@ namespace Ombi.Controllers.V1
}
var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async () => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));
var images = await FanartTvApi.GetTvImages(tvdbid, key.Value);
var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvdbid}", async () => await FanartTvApi.GetTvImages(tvdbid, key.Value), DateTime.Now.AddDays(1));
if (images == null)
{
@ -216,11 +216,13 @@ namespace Ombi.Controllers.V1
if (moviesArray.Length > 0)
{
var item = rand.Next(moviesArray.Length);
var result = await FanartTvApi.GetMovieImages(moviesArray[item].ToString(), key.Value);
var result = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{moviesArray[item]}", async () => await FanartTvApi.GetMovieImages(moviesArray[item].ToString(), key.Value), DateTime.Now.AddDays(1));
while (!result.moviebackground.Any())
{
result = await FanartTvApi.GetMovieImages(moviesArray[item].ToString(), key.Value);
item = rand.Next(moviesArray.Length);
result = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{moviesArray[item]}", async () => await FanartTvApi.GetMovieImages(moviesArray[item].ToString(), key.Value), DateTime.Now.AddDays(1));
}
var otherRand = new Random();
@ -231,11 +233,12 @@ namespace Ombi.Controllers.V1
if (tvArray.Length > 0)
{
var item = rand.Next(tvArray.Length);
var result = await FanartTvApi.GetTvImages(tvArray[item], key.Value);
var result = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvArray[item]}", async () => await FanartTvApi.GetTvImages(tvArray[item], key.Value), DateTime.Now.AddDays(1));
while (!result.showbackground.Any())
{
result = await FanartTvApi.GetTvImages(tvArray[item], key.Value);
item = rand.Next(tvArray.Length);
result = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvArray[item]}", async () => await FanartTvApi.GetTvImages(tvArray[item], key.Value), DateTime.Now.AddDays(1));
}
var otherRand = new Random();
var res = otherRand.Next(result.showbackground.Length);

@ -21,7 +21,7 @@
}
},
"Ombi": {
"commandName": "IISExpress",
"commandName": "Project",
"commandLineArgs": "--host http://*:3577",
"applicationUrl": "http://localhost:3577/"
}

@ -42,7 +42,7 @@ namespace Ombi
Console.WriteLine(env.ContentRootPath);
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", false, false)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
.AddEnvironmentVariables();
Configuration = builder.Build();

@ -34,7 +34,12 @@
260513,
372058,
299536,
383498
383498,
330457,
429617,
475557,
420818,
283995
],
"TvShows": [
121361,
@ -45,7 +50,10 @@
275274,
305288,
296762,
280619
280619,
305074,
277165,
362696
]
},
// Please ignore the below

Loading…
Cancel
Save