mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Reworked the cacher, fixed the memory leak. No more logging within tight loops.
This commit is contained in:
parent
98662ab74e
commit
4bccb8fcf0
4 changed files with 25 additions and 21 deletions
|
@ -224,7 +224,7 @@ namespace PlexRequests.Api
|
||||||
var request = new RestRequest
|
var request = new RestRequest
|
||||||
{
|
{
|
||||||
Method = Method.GET,
|
Method = Method.GET,
|
||||||
Resource = "/library/metadata/{ratingKey}/allLeaves"
|
Resource = "/library/metadata/{ratingKey}"
|
||||||
};
|
};
|
||||||
|
|
||||||
request.AddUrlSegment("ratingKey", ratingKey);
|
request.AddUrlSegment("ratingKey", ratingKey);
|
||||||
|
|
|
@ -244,13 +244,11 @@ namespace PlexRequests.Services.Jobs
|
||||||
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
|
var episodes = Cache.Get<List<PlexEpisodeModel>>(CacheKeys.PlexEpisodes);
|
||||||
if (episodes == null)
|
if (episodes == null)
|
||||||
{
|
{
|
||||||
Log.Trace("Episode is not available. tvdbid: {0}, season: {1}, episode: {2}",theTvDbId, season, episode);
|
Log.Info("Episode cache info is not available. tvdbid: {0}, season: {1}, episode: {2}",theTvDbId, season, episode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach (var result in episodes)
|
foreach (var result in episodes)
|
||||||
{
|
{
|
||||||
Log.Trace("Result:");
|
|
||||||
Log.Trace(result.DumpJson());
|
|
||||||
if (result.Episodes.ProviderId.Equals(theTvDbId) && result.Episodes.EpisodeNumber == episode && result.Episodes.SeasonNumber == season)
|
if (result.Episodes.ProviderId.Equals(theTvDbId) && result.Episodes.EpisodeNumber == episode && result.Episodes.SeasonNumber == season)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -59,11 +59,12 @@ namespace PlexRequests.Services.Jobs
|
||||||
private ICacheProvider Cache { get; }
|
private ICacheProvider Cache { get; }
|
||||||
private IJobRecord Job { get; }
|
private IJobRecord Job { get; }
|
||||||
private const int ResultCount = 25;
|
private const int ResultCount = 25;
|
||||||
|
private const string PlexType = "episode";
|
||||||
|
|
||||||
|
|
||||||
public void CacheEpisodes()
|
public void CacheEpisodes()
|
||||||
{
|
{
|
||||||
var results = new List<PlexSearch>();
|
var results = new PlexSearch();
|
||||||
var settings = Plex.GetSettings();
|
var settings = Plex.GetSettings();
|
||||||
var sections = PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri);
|
var sections = PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri);
|
||||||
var tvSection = sections.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
|
var tvSection = sections.Directories.FirstOrDefault(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
@ -73,29 +74,28 @@ namespace PlexRequests.Services.Jobs
|
||||||
int totalSize;
|
int totalSize;
|
||||||
|
|
||||||
var episodes = PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount);
|
var episodes = PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount);
|
||||||
results.Add(episodes);
|
results = episodes;
|
||||||
int.TryParse(episodes.TotalSize, out totalSize);
|
int.TryParse(episodes.TotalSize, out totalSize);
|
||||||
|
|
||||||
currentPosition += ResultCount;
|
currentPosition += ResultCount;
|
||||||
while (currentPosition < totalSize)
|
while (currentPosition < totalSize)
|
||||||
{
|
{
|
||||||
results.Add(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount));
|
results.Video.AddRange(PlexApi.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, tvSectionId, currentPosition, ResultCount).Video);
|
||||||
currentPosition += ResultCount;
|
currentPosition += ResultCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filteredList = results.Video.Where(x => x.Type.Equals(PlexType, StringComparison.InvariantCultureIgnoreCase));
|
||||||
var episodesModel = new List<PlexEpisodeModel>();
|
var episodesModel = new List<PlexEpisodeModel>();
|
||||||
var metadataList = new List<PlexEpisodeMetadata>();
|
var metadataList = new List<PlexEpisodeMetadata>();
|
||||||
foreach (var r in results)
|
|
||||||
|
foreach (var video in filteredList)
|
||||||
{
|
{
|
||||||
foreach (var video in r.Video)
|
var ratingKey = video.RatingKey;
|
||||||
{
|
var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey);
|
||||||
var ratingKey = video.RatingKey;
|
metadataList.Add(metadata);
|
||||||
var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, ratingKey);
|
|
||||||
metadataList.Add(metadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var m in metadataList)
|
foreach (var m in metadataList)
|
||||||
{
|
{
|
||||||
foreach (var video in m.Video)
|
foreach (var video in m.Video)
|
||||||
|
@ -111,7 +111,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (results.Any())
|
if (results.Video.Any())
|
||||||
{
|
{
|
||||||
Cache.Set(CacheKeys.PlexEpisodes, episodesModel, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
Cache.Set(CacheKeys.PlexEpisodes, episodesModel, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||||
}
|
}
|
||||||
|
|
|
@ -951,11 +951,13 @@ namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
var seriesId = (int)Request.Query.tvId;
|
var seriesId = (int)Request.Query.tvId;
|
||||||
var s = await SonarrService.GetSettingsAsync();
|
var s = await SonarrService.GetSettingsAsync();
|
||||||
|
var sonarrEnabled = s.Enabled;
|
||||||
var allResults = await RequestService.GetAllAsync();
|
var allResults = await RequestService.GetAllAsync();
|
||||||
|
|
||||||
var seriesTask = Task.Run(
|
var seriesTask = Task.Run(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
if (s.Enabled)
|
if (sonarrEnabled)
|
||||||
{
|
{
|
||||||
var allSeries = SonarrApi.GetSeries(s.ApiKey, s.FullUri);
|
var allSeries = SonarrApi.GetSeries(s.ApiKey, s.FullUri);
|
||||||
var selectedSeries = allSeries.FirstOrDefault(x => x.tvdbId == seriesId) ?? new Series();
|
var selectedSeries = allSeries.FirstOrDefault(x => x.tvdbId == seriesId) ?? new Series();
|
||||||
|
@ -972,9 +974,13 @@ namespace PlexRequests.UI.Modules
|
||||||
var show = await Task.Run(() => TvApi.ShowLookupByTheTvDbId(seriesId));
|
var show = await Task.Run(() => TvApi.ShowLookupByTheTvDbId(seriesId));
|
||||||
var seasons = await Task.Run(() => TvApi.EpisodeLookup(show.id));
|
var seasons = await Task.Run(() => TvApi.EpisodeLookup(show.id));
|
||||||
|
|
||||||
var sonarrSeries = await seriesTask;
|
var sonarrEpisodes = new List<SonarrEpisodes>();
|
||||||
var sonarrEp = SonarrApi.GetEpisodes(sonarrSeries.id.ToString(), s.ApiKey, s.FullUri);
|
if (sonarrEnabled)
|
||||||
var sonarrEpisodes = sonarrEp?.ToList() ?? new List<SonarrEpisodes>();
|
{
|
||||||
|
var sonarrSeries = await seriesTask;
|
||||||
|
var sonarrEp = SonarrApi.GetEpisodes(sonarrSeries.id.ToString(), s.ApiKey, s.FullUri);
|
||||||
|
sonarrEpisodes = sonarrEp?.ToList() ?? new List<SonarrEpisodes>();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var ep in seasons)
|
foreach (var ep in seasons)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue