Added logic to stop duplicate shows from being announced using redis cache
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using TMDbLib.Utilities.Converters;
|
using TMDbLib.Utilities.Converters;
|
||||||
@@ -20,7 +21,7 @@ public class TMDBCache
|
|||||||
{
|
{
|
||||||
var db = redis.GetDatabase();
|
var db = redis.GetDatabase();
|
||||||
String jsonItem = JsonSerializer.Serialize(item);
|
String jsonItem = JsonSerializer.Serialize(item);
|
||||||
db.StringSetAsync(key, jsonItem, CacheExpiration);
|
await db.StringSetAsync(key, jsonItem, CacheExpiration);
|
||||||
}
|
}
|
||||||
public async Task<TMDBCacheItem> GetCacheItem(String key)
|
public async Task<TMDBCacheItem> GetCacheItem(String key)
|
||||||
{
|
{
|
||||||
@@ -32,4 +33,14 @@ public class TMDBCache
|
|||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public async Task<bool> KeyExists(String key)
|
||||||
|
{
|
||||||
|
var db = redis.GetDatabase();
|
||||||
|
return await db.KeyExistsAsync(key);
|
||||||
|
}
|
||||||
|
public async Task SetPair(String key, String value)
|
||||||
|
{
|
||||||
|
var db = redis.GetDatabase();
|
||||||
|
await db.StringSetAsync(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using AnimeAnnouncer.Cache;
|
using AnimeAnnouncer.Cache;
|
||||||
using AnimeAnnouncer.RSS;
|
using AnimeAnnouncer.RSS;
|
||||||
using Mastonet;
|
using Mastonet;
|
||||||
@@ -166,7 +167,16 @@ namespace AnimeAnnouncer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Announce
|
// Announce if unique
|
||||||
|
if(await tmdbCache.KeyExists($"ShowAnnounced-{supposedShowId}"))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{title} has been previously announced, so avoiding announcing it again.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ = tmdbCache.SetPair($"ShowAnnounced-{supposedShowId}", "1");
|
||||||
|
}
|
||||||
if(mastodonClient != null)
|
if(mastodonClient != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user