mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Handling rush conditions on collection/show/season register
This commit is contained in:
parent
51fa75214b
commit
33d9c5d9b4
@ -49,21 +49,6 @@ namespace Kyoo
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DatabaseFactory
|
|
||||||
{
|
|
||||||
private readonly DbContextOptions<DatabaseContext> _options;
|
|
||||||
|
|
||||||
public DatabaseFactory(DbContextOptions<DatabaseContext> options)
|
|
||||||
{
|
|
||||||
_options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseContext NewDatabaseConnection()
|
|
||||||
{
|
|
||||||
return new DatabaseContext(_options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DatabaseContext : DbContext
|
public class DatabaseContext : DbContext
|
||||||
{
|
{
|
||||||
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
||||||
|
@ -43,11 +43,6 @@ namespace Kyoo
|
|||||||
services.AddControllers().AddNewtonsoftJson();
|
services.AddControllers().AddNewtonsoftJson();
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|
||||||
services.AddSingleton(x => new DatabaseFactory(
|
|
||||||
new DbContextOptionsBuilder<DatabaseContext>()
|
|
||||||
.UseLazyLoadingProxies()
|
|
||||||
.UseNpgsql(_configuration.GetConnectionString("Database")).Options));
|
|
||||||
|
|
||||||
services.AddDbContext<DatabaseContext>(options =>
|
services.AddDbContext<DatabaseContext>(options =>
|
||||||
{
|
{
|
||||||
options.UseLazyLoadingProxies()
|
options.UseLazyLoadingProxies()
|
||||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Models.Exceptions;
|
||||||
using Kyoo.Models.Watch;
|
using Kyoo.Models.Watch;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
@ -40,7 +41,9 @@ namespace Kyoo.Controllers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string argument = null)
|
public async Task Run(IServiceProvider serviceProvider,
|
||||||
|
CancellationToken cancellationToken,
|
||||||
|
string argument = null)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_thumbnailsManager = serviceProvider.GetService<IThumbnailsManager>();
|
_thumbnailsManager = serviceProvider.GetService<IThumbnailsManager>();
|
||||||
@ -68,7 +71,6 @@ namespace Kyoo.Controllers
|
|||||||
library.Providers = library.Providers;
|
library.Providers = library.Providers;
|
||||||
|
|
||||||
await Task.WhenAll(libraries.Select(x => Scan(x, episodes, cancellationToken)).ToArray());
|
await Task.WhenAll(libraries.Select(x => Scan(x, episodes, cancellationToken)).ToArray());
|
||||||
Console.WriteLine("Done.");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -111,6 +113,8 @@ namespace Kyoo.Controllers
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Should register shows first to prevent all tasks of a same show to register it 150+ times.
|
||||||
|
|
||||||
return Task.WhenAll(files.Select(file =>
|
return Task.WhenAll(files.Select(file =>
|
||||||
{
|
{
|
||||||
if (!IsVideo(file) || episodes.Any(x => x.Path == file))
|
if (!IsVideo(file) || episodes.Any(x => x.Path == file))
|
||||||
@ -118,6 +122,7 @@ namespace Kyoo.Controllers
|
|||||||
string relativePath = file.Substring(path.Length);
|
string relativePath = file.Substring(path.Length);
|
||||||
return RegisterFile(file, relativePath, library, cancellationToken);
|
return RegisterFile(file, relativePath, library, cancellationToken);
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
|
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +171,16 @@ namespace Kyoo.Controllers
|
|||||||
if (collection != null)
|
if (collection != null)
|
||||||
return collection;
|
return collection;
|
||||||
collection = await _metadataProvider.GetCollectionFromName(collectionName, library);
|
collection = await _metadataProvider.GetCollectionFromName(collectionName, library);
|
||||||
await libraryManager.RegisterCollection(collection);
|
|
||||||
return collection;
|
try
|
||||||
|
{
|
||||||
|
await libraryManager.RegisterCollection(collection);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
catch (DuplicatedItemException)
|
||||||
|
{
|
||||||
|
return await libraryManager.GetCollection(collection.Slug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Show> GetShow(ILibraryManager libraryManager,
|
private async Task<Show> GetShow(ILibraryManager libraryManager,
|
||||||
@ -182,10 +195,18 @@ namespace Kyoo.Controllers
|
|||||||
show = await _metadataProvider.SearchShow(showTitle, isMovie, library);
|
show = await _metadataProvider.SearchShow(showTitle, isMovie, library);
|
||||||
show.Path = showPath;
|
show.Path = showPath;
|
||||||
show.People = await _metadataProvider.GetPeople(show, library);
|
show.People = await _metadataProvider.GetPeople(show, library);
|
||||||
await libraryManager.RegisterShow(show);
|
|
||||||
await _thumbnailsManager.Validate(show.People);
|
try
|
||||||
await _thumbnailsManager.Validate(show);
|
{
|
||||||
return show;
|
await libraryManager.RegisterShow(show);
|
||||||
|
await _thumbnailsManager.Validate(show.People);
|
||||||
|
await _thumbnailsManager.Validate(show);
|
||||||
|
return show;
|
||||||
|
}
|
||||||
|
catch (DuplicatedItemException)
|
||||||
|
{
|
||||||
|
return await libraryManager.GetShow(show.Slug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Season> GetSeason(ILibraryManager libraryManager,
|
private async Task<Season> GetSeason(ILibraryManager libraryManager,
|
||||||
@ -199,8 +220,15 @@ namespace Kyoo.Controllers
|
|||||||
if (season == null)
|
if (season == null)
|
||||||
{
|
{
|
||||||
season = await _metadataProvider.GetSeason(show, seasonNumber, library);
|
season = await _metadataProvider.GetSeason(show, seasonNumber, library);
|
||||||
await libraryManager.RegisterSeason(season);
|
try
|
||||||
await _thumbnailsManager.Validate(season);
|
{
|
||||||
|
await libraryManager.RegisterSeason(season);
|
||||||
|
await _thumbnailsManager.Validate(season);
|
||||||
|
}
|
||||||
|
catch (DuplicatedItemException)
|
||||||
|
{
|
||||||
|
season = await libraryManager.GetSeason(show.Slug, season.SeasonNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
season.Show = show;
|
season.Show = show;
|
||||||
return season;
|
return season;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user