mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Some performance improvements around the new TV stuff
This commit is contained in:
parent
4bccb8fcf0
commit
53f806fc71
4 changed files with 225 additions and 179 deletions
|
@ -37,22 +37,21 @@ namespace PlexRequests.Helpers
|
|||
{
|
||||
public static class LoggingHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// WARNING, This method uses up a LOT of memory and can lead to leaks.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns></returns>
|
||||
public static string DumpJson(this object value)
|
||||
{
|
||||
var dumpTarget = value;
|
||||
object dumpTarget;
|
||||
//if this is a string that contains a JSON object, do a round-trip serialization to format it:
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null)
|
||||
{
|
||||
if (stringValue.Trim().StartsWith("{", StringComparison.Ordinal))
|
||||
{
|
||||
var obj = JsonConvert.DeserializeObject(stringValue);
|
||||
dumpTarget = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpTarget = stringValue;
|
||||
}
|
||||
dumpTarget = stringValue.Trim().StartsWith("{", StringComparison.Ordinal)
|
||||
? JsonConvert.SerializeObject(JsonConvert.DeserializeObject(stringValue), Formatting.Indented)
|
||||
: stringValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -73,7 +72,8 @@ namespace PlexRequests.Helpers
|
|||
CommandType = CommandType.Text,
|
||||
ConnectionString = connectionString,
|
||||
DBProvider = "Mono.Data.Sqlite.SqliteConnection, Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756",
|
||||
Name = "database"
|
||||
Name = "database",
|
||||
|
||||
};
|
||||
|
||||
var messageParam = new DatabaseParameterInfo { Name = "@Message", Layout = "${message}" };
|
||||
|
@ -94,7 +94,7 @@ namespace PlexRequests.Helpers
|
|||
config.AddTarget("database", databaseTarget);
|
||||
|
||||
// Step 4. Define rules
|
||||
var rule1 = new LoggingRule("*", LogLevel.Info, databaseTarget);
|
||||
var rule1 = new LoggingRule("*", LogLevel.Debug, databaseTarget);
|
||||
config.LoggingRules.Add(rule1);
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace PlexRequests.Helpers
|
|||
CreateDirs = true
|
||||
};
|
||||
config.AddTarget(fileTarget);
|
||||
var rule2 = new LoggingRule("*", LogLevel.Info, fileTarget);
|
||||
var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
|
||||
config.LoggingRules.Add(rule2);
|
||||
|
||||
// Step 5. Activate the configuration
|
||||
|
|
|
@ -39,5 +39,16 @@ namespace PlexRequests.Services.Interfaces
|
|||
List<PlexAlbum> GetPlexAlbums();
|
||||
bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist);
|
||||
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
|
||||
/// <summary>
|
||||
/// Gets the episode's stored in the cache.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<PlexEpisodeModel> GetEpisodeCache();
|
||||
/// <summary>
|
||||
/// Gets the episode's stored in the cache and then filters on the TheTvDBId.
|
||||
/// </summary>
|
||||
/// <param name="theTvDbId">The tv database identifier.</param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<PlexEpisodeModel> GetEpisodeCache(int theTvDbId);
|
||||
}
|
||||
}
|
|
@ -257,6 +257,38 @@ namespace PlexRequests.Services.Jobs
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the episode's stored in the cache.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<PlexEpisodeModel> GetEpisodeCache()
|
||||
{
|
||||
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
|
||||
if (episodes == null)
|
||||
{
|
||||
Log.Info("Episode cache info is not available.");
|
||||
return new List<PlexEpisodeModel>();
|
||||
}
|
||||
return episodes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the episode's stored in the cache and then filters on the TheTvDBId.
|
||||
/// </summary>
|
||||
/// <param name="theTvDbId">The tv database identifier.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<PlexEpisodeModel> GetEpisodeCache(int theTvDbId)
|
||||
{
|
||||
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
|
||||
if (episodes == null)
|
||||
{
|
||||
Log.Info("Episode cache info is not available.");
|
||||
return new List<PlexEpisodeModel>();
|
||||
}
|
||||
|
||||
return episodes.Where(x => x.Episodes.ProviderId == theTvDbId.ToString());
|
||||
}
|
||||
|
||||
public List<PlexAlbum> GetPlexAlbums()
|
||||
{
|
||||
var albums = new List<PlexAlbum>();
|
||||
|
|
|
@ -608,9 +608,10 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
if (episodeRequest)
|
||||
{
|
||||
var cachedEpisodes = Checker.GetEpisodeCache().ToList();
|
||||
foreach (var d in difference)
|
||||
{
|
||||
if (Checker.IsEpisodeAvailable(providerId, d.SeasonNumber, d.EpisodeNumber))
|
||||
if (cachedEpisodes.Any(x => x.Episodes.SeasonNumber == d.SeasonNumber && x.Episodes.EpisodeNumber == d.EpisodeNumber && x.Episodes.ProviderId == providerId))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {Resources.UI.Search_AlreadyInPlex}" });
|
||||
}
|
||||
|
@ -982,13 +983,15 @@ namespace PlexRequests.UI.Modules
|
|||
sonarrEpisodes = sonarrEp?.ToList() ?? new List<SonarrEpisodes>();
|
||||
}
|
||||
|
||||
var plexCache = Checker.GetEpisodeCache(seriesId).ToList();
|
||||
|
||||
foreach (var ep in seasons)
|
||||
{
|
||||
var requested = dbDbShow?.Episodes
|
||||
.Any(episodesModel =>
|
||||
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber) ?? false;
|
||||
|
||||
var alreadyInPlex = Checker.IsEpisodeAvailable(seriesId.ToString(), ep.season, ep.number);
|
||||
var alreadyInPlex = plexCache.Any(x => x.Episodes.EpisodeNumber == ep.number && x.Episodes.SeasonNumber == ep.season);
|
||||
var inSonarr = sonarrEpisodes.Any(x => x.seasonNumber == ep.season && x.episodeNumber == ep.number && x.monitored);
|
||||
|
||||
model.Add(new EpisodeListViewModel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue