mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Since we are multithreading, we should use a threadsafe type to store the episodes to prevent any threading or race conditions.
This commit is contained in:
parent
5471a77480
commit
f112af7e85
2 changed files with 17 additions and 12 deletions
|
@ -25,6 +25,7 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -100,7 +101,7 @@ namespace PlexRequests.Services.Jobs
|
|||
currentPosition += ResultCount;
|
||||
}
|
||||
|
||||
var entities = new HashSet<PlexEpisodes>();
|
||||
var entities = new ConcurrentDictionary<PlexEpisodes, byte>();
|
||||
|
||||
Parallel.ForEach(videoHashset, video =>
|
||||
{
|
||||
|
@ -111,15 +112,17 @@ namespace PlexRequests.Services.Jobs
|
|||
foreach (var metadataVideo in metadata.Video)
|
||||
{
|
||||
var epInfo = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(metadataVideo.Guid);
|
||||
entities.Add(new PlexEpisodes
|
||||
{
|
||||
EpisodeNumber = epInfo.EpisodeNumber,
|
||||
EpisodeTitle = metadataVideo.Title,
|
||||
ProviderId = epInfo.ProviderId,
|
||||
RatingKey = metadataVideo.RatingKey,
|
||||
SeasonNumber = epInfo.SeasonNumber,
|
||||
ShowTitle = metadataVideo.GrandparentThumb
|
||||
});
|
||||
entities.TryAdd(
|
||||
new PlexEpisodes
|
||||
{
|
||||
EpisodeNumber = epInfo.EpisodeNumber,
|
||||
EpisodeTitle = metadataVideo.Title,
|
||||
ProviderId = epInfo.ProviderId,
|
||||
RatingKey = metadataVideo.RatingKey,
|
||||
SeasonNumber = epInfo.SeasonNumber,
|
||||
ShowTitle = metadataVideo.GrandparentThumb
|
||||
},
|
||||
1);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -127,7 +130,7 @@ namespace PlexRequests.Services.Jobs
|
|||
Repo.DeleteAll(TableName);
|
||||
|
||||
// Insert the new items
|
||||
var result = Repo.BatchInsert(entities, TableName, typeof(PlexEpisodes).GetPropertyNames());
|
||||
var result = Repo.BatchInsert(entities.Select(x => x.Key).ToList(), TableName, typeof(PlexEpisodes).GetPropertyNames());
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
|
|
@ -101,6 +101,7 @@ CREATE TABLE IF NOT EXISTS PlexUsers
|
|||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id);
|
||||
|
||||
BEGIN;
|
||||
CREATE TABLE IF NOT EXISTS PlexEpisodes
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -112,4 +113,5 @@ CREATE TABLE IF NOT EXISTS PlexEpisodes
|
|||
EpisodeNumber INTEGER NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS PlexEpisodes_Id ON PlexEpisodes (Id);
|
||||
CREATE INDEX IF NOT EXISTS PlexEpisodes_ProviderId ON PlexEpisodes (ProviderId);
|
||||
CREATE INDEX IF NOT EXISTS PlexEpisodes_ProviderId ON PlexEpisodes (ProviderId);
|
||||
COMMIT;
|
Loading…
Add table
Add a link
Reference in a new issue