Made the episode check parallel

pull/470/head
tidusjar 9 years ago
parent 25b8e2e78b
commit 1fa32d29ea

@ -27,6 +27,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using NLog; using NLog;
@ -91,8 +92,6 @@ namespace PlexRequests.Services.Jobs
// Parse the total amount of episodes // Parse the total amount of episodes
int.TryParse(episodes.TotalSize, out totalSize); int.TryParse(episodes.TotalSize, out totalSize);
currentPosition += ResultCount;
// Get all of the episodes in batches until we them all (Got'a catch 'em all!) // Get all of the episodes in batches until we them all (Got'a catch 'em all!)
while (currentPosition < totalSize) while (currentPosition < totalSize)
{ {
@ -103,9 +102,8 @@ namespace PlexRequests.Services.Jobs
var entities = new HashSet<PlexEpisodes>(); var entities = new HashSet<PlexEpisodes>();
foreach (var video in videoHashset) Parallel.ForEach(videoHashset, video =>
{ {
// Get the individual episode Metadata (This is for us to get the TheTVDBId which also includes the episode number and season number) // Get the individual episode Metadata (This is for us to get the TheTVDBId which also includes the episode number and season number)
var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, video.RatingKey); var metadata = PlexApi.GetEpisodeMetaData(settings.PlexAuthToken, settings.FullUri, video.RatingKey);
@ -113,28 +111,27 @@ namespace PlexRequests.Services.Jobs
foreach (var metadataVideo in metadata.Video) foreach (var metadataVideo in metadata.Video)
{ {
var epInfo = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(metadataVideo.Guid); var epInfo = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(metadataVideo.Guid);
entities.Add( entities.Add(new PlexEpisodes
new PlexEpisodes {
{ EpisodeNumber = epInfo.EpisodeNumber,
EpisodeNumber = epInfo.EpisodeNumber, EpisodeTitle = metadataVideo.Title,
EpisodeTitle = metadataVideo.Title, ProviderId = epInfo.ProviderId,
ProviderId = epInfo.ProviderId, RatingKey = metadataVideo.RatingKey,
RatingKey = metadataVideo.RatingKey, SeasonNumber = epInfo.SeasonNumber,
SeasonNumber = epInfo.SeasonNumber, ShowTitle = metadataVideo.GrandparentThumb
ShowTitle = metadataVideo.GrandparentThumb });
});
} }
} });
// Delete all of the current items // Delete all of the current items
Repo.DeleteAll(TableName); Repo.DeleteAll(TableName);
// TODO Fix the datatype mismatch...
// Insert the new items // Insert the new items
var result = Repo.BatchInsert(entities, TableName, typeof(PlexEpisodes).GetPropertyNames()); var result = Repo.BatchInsert(entities, TableName, typeof(PlexEpisodes).GetPropertyNames());
if (!result) if (!result)
{ {
Log.Error("Saving the plex episodes to the DB Failed"); Log.Error("Saving the Plex episodes to the DB Failed");
} }
} }

Loading…
Cancel
Save