mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 04:49:33 -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
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -100,7 +101,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
currentPosition += ResultCount;
|
currentPosition += ResultCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entities = new HashSet<PlexEpisodes>();
|
var entities = new ConcurrentDictionary<PlexEpisodes, byte>();
|
||||||
|
|
||||||
Parallel.ForEach(videoHashset, video =>
|
Parallel.ForEach(videoHashset, video =>
|
||||||
{
|
{
|
||||||
|
@ -111,15 +112,17 @@ 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(new PlexEpisodes
|
entities.TryAdd(
|
||||||
{
|
new PlexEpisodes
|
||||||
EpisodeNumber = epInfo.EpisodeNumber,
|
{
|
||||||
EpisodeTitle = metadataVideo.Title,
|
EpisodeNumber = epInfo.EpisodeNumber,
|
||||||
ProviderId = epInfo.ProviderId,
|
EpisodeTitle = metadataVideo.Title,
|
||||||
RatingKey = metadataVideo.RatingKey,
|
ProviderId = epInfo.ProviderId,
|
||||||
SeasonNumber = epInfo.SeasonNumber,
|
RatingKey = metadataVideo.RatingKey,
|
||||||
ShowTitle = metadataVideo.GrandparentThumb
|
SeasonNumber = epInfo.SeasonNumber,
|
||||||
});
|
ShowTitle = metadataVideo.GrandparentThumb
|
||||||
|
},
|
||||||
|
1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,7 +130,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
Repo.DeleteAll(TableName);
|
Repo.DeleteAll(TableName);
|
||||||
|
|
||||||
// Insert the new items
|
// 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)
|
if (!result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,6 +101,7 @@ CREATE TABLE IF NOT EXISTS PlexUsers
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id);
|
CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id);
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
CREATE TABLE IF NOT EXISTS PlexEpisodes
|
CREATE TABLE IF NOT EXISTS PlexEpisodes
|
||||||
(
|
(
|
||||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
@ -112,4 +113,5 @@ CREATE TABLE IF NOT EXISTS PlexEpisodes
|
||||||
EpisodeNumber INTEGER NOT NULL
|
EpisodeNumber INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS PlexEpisodes_Id ON PlexEpisodes (Id);
|
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