Implemented redis caching; made docker build script for VS code builds
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using AnimeAnnouncer.Cache;
|
||||
using System.ComponentModel;
|
||||
using AnimeAnnouncer.Cache;
|
||||
using AnimeAnnouncer.RSS;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TMDbLib.Client;
|
||||
|
||||
namespace AnimeAnnouncer
|
||||
@@ -34,6 +36,7 @@ namespace AnimeAnnouncer
|
||||
if(!String.IsNullOrEmpty(redisCacheConnectionString))
|
||||
{
|
||||
tmdbCache = new TMDBCache(redisCacheConnectionString);
|
||||
Console.WriteLine("Using cache");
|
||||
}
|
||||
|
||||
nyaaIndexer.NewPost += OnNewPost;
|
||||
@@ -77,9 +80,33 @@ namespace AnimeAnnouncer
|
||||
return;
|
||||
}
|
||||
|
||||
int latestSeasonNumber = 0, latestEpisodeNumber = 0, supposedShowId = 0;
|
||||
|
||||
if(tmdbCache != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cachedShow = await tmdbCache.GetCacheItem($"ShowCache-{title}");
|
||||
if(cachedShow != null)
|
||||
{
|
||||
Console.WriteLine("Cache hit");
|
||||
latestSeasonNumber = cachedShow.LatestSeasonNumber;
|
||||
latestEpisodeNumber = cachedShow.LastEpisodeNumber;
|
||||
supposedShowId = cachedShow.ShowID;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if(supposedShowId == 0)
|
||||
{ //no cache hit
|
||||
|
||||
var searchResults = await tmdbClient.SearchTvShowAsync(title);
|
||||
|
||||
var supposedShowId = searchResults.Results.First().Id;
|
||||
supposedShowId = searchResults.Results.First().Id;
|
||||
|
||||
var showResult = await tmdbClient.GetTvShowAsync(supposedShowId);
|
||||
|
||||
@@ -91,15 +118,41 @@ namespace AnimeAnnouncer
|
||||
return;
|
||||
}
|
||||
|
||||
if(latestSeason.SeasonNumber != int.Parse(season))
|
||||
latestSeasonNumber = latestSeason.SeasonNumber;
|
||||
|
||||
latestEpisodeNumber = latestSeason.EpisodeCount;
|
||||
|
||||
if(tmdbCache != null && searchResults != null)
|
||||
{
|
||||
Console.WriteLine($"Failing release due to TMDB's season number {latestSeason.SeasonNumber} not matching title season {season}");
|
||||
try
|
||||
{
|
||||
tmdbCache.SetCacheItem($"ShowCache-{title}", new TMDBCacheItem()
|
||||
{
|
||||
Title = title,
|
||||
ShowID = supposedShowId,
|
||||
LatestSeasonNumber = latestSeason.SeasonNumber,
|
||||
LastEpisodeNumber = latestSeason.EpisodeCount
|
||||
}).Start();
|
||||
Console.WriteLine($"{title} Added to cache");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(latestSeasonNumber != int.Parse(season))
|
||||
{
|
||||
Console.WriteLine($"Failing release due to TMDB's season number {latestSeasonNumber} not matching title season {season}");
|
||||
return;
|
||||
}
|
||||
|
||||
if(latestSeason.EpisodeCount != int.Parse(episode))
|
||||
if(latestEpisodeNumber != int.Parse(episode))
|
||||
{
|
||||
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestSeason.EpisodeCount} not matching title episode number {episode}");
|
||||
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestEpisodeNumber} not matching title episode number {episode}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user