mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
#114 start caching quality profiles. Set the cache on startup and when obtaining quality profiles in settings
This commit is contained in:
parent
08b14d0164
commit
e8c222f66e
6 changed files with 81 additions and 14 deletions
|
@ -29,5 +29,8 @@ namespace PlexRequests.Core
|
|||
public class CacheKeys
|
||||
{
|
||||
public const string TvDbToken = "TheTvDbApiToken";
|
||||
public const string SonarrQualityProfiles = "SonarrQualityProfiles";
|
||||
public const string SickRageQualityProfiles = "SickRageQualityProfiles";
|
||||
public const string CouchPotatoQualityProfiles = "CouchPotatoQualityProfiles";
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ using PlexRequests.Helpers;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Repository;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
|
@ -115,6 +116,52 @@ namespace PlexRequests.Core
|
|||
s.SaveSettings(defaultSettings);
|
||||
}
|
||||
|
||||
public async void CacheQualityProfiles()
|
||||
{
|
||||
var mc = new MemoryCacheProvider();
|
||||
|
||||
try
|
||||
{
|
||||
CacheSonarrQualityProfiles(mc);
|
||||
CacheCouchPotatoQualityProfiles(mc);
|
||||
// we don't need to cache sickrage profiles, those are static
|
||||
// TODO: cache headphones profiles?
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Log.Error("Failed to cache quality profiles on startup!");
|
||||
}
|
||||
}
|
||||
|
||||
private async void CacheSonarrQualityProfiles(MemoryCacheProvider cacheProvider)
|
||||
{
|
||||
var sonarrSettingsService = new SettingsServiceV2<SonarrSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||
var sonarrSettings = sonarrSettingsService.GetSettings();
|
||||
if (sonarrSettings.Enabled) {
|
||||
cacheProvider.GetOrSet(CacheKeys.SonarrQualityProfiles, () =>
|
||||
{
|
||||
SonarrApi sonarrApi = new SonarrApi();
|
||||
return sonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async void CacheCouchPotatoQualityProfiles(MemoryCacheProvider cacheProvider)
|
||||
{
|
||||
var cpSettingsService = new SettingsServiceV2<CouchPotatoSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||
var cpSettings = cpSettingsService.GetSettings();
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
cacheProvider.GetOrSet(CacheKeys.CouchPotatoQualityProfiles, () =>
|
||||
{
|
||||
CouchPotatoApi cpApi = new CouchPotatoApi();
|
||||
return cpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateDbFrom1300() // TODO: Remove in v1.7
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue