Implemented redis caching; made docker build script for VS code builds

This commit is contained in:
2024-09-24 15:57:37 -04:00
parent 92d35cae2f
commit 21ea17e906
2 changed files with 73 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
using AnimeAnnouncer.Cache; using System.ComponentModel;
using AnimeAnnouncer.Cache;
using AnimeAnnouncer.RSS; using AnimeAnnouncer.RSS;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using TMDbLib.Client; using TMDbLib.Client;
namespace AnimeAnnouncer namespace AnimeAnnouncer
@@ -34,6 +36,7 @@ namespace AnimeAnnouncer
if(!String.IsNullOrEmpty(redisCacheConnectionString)) if(!String.IsNullOrEmpty(redisCacheConnectionString))
{ {
tmdbCache = new TMDBCache(redisCacheConnectionString); tmdbCache = new TMDBCache(redisCacheConnectionString);
Console.WriteLine("Using cache");
} }
nyaaIndexer.NewPost += OnNewPost; nyaaIndexer.NewPost += OnNewPost;
@@ -77,9 +80,33 @@ namespace AnimeAnnouncer
return; 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 searchResults = await tmdbClient.SearchTvShowAsync(title);
var supposedShowId = searchResults.Results.First().Id; supposedShowId = searchResults.Results.First().Id;
var showResult = await tmdbClient.GetTvShowAsync(supposedShowId); var showResult = await tmdbClient.GetTvShowAsync(supposedShowId);
@@ -91,15 +118,41 @@ namespace AnimeAnnouncer
return; 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; 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; return;
} }

2
build.sh Executable file
View File

@@ -0,0 +1,2 @@
docker build --pull --rm -f "AnimeAnnouncer/Dockerfile" -t dtr.chrispr.org/animeannouncer:latest .
docker push dtr.chrispr.org/animeannouncer:latest