From a6d310732919e7c2192dccc02a6bb8dc2bb26101 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 25 Dec 2020 23:46:32 +0100 Subject: [PATCH] Fixing some issues with the crawler & most issues of the ressource editor --- Kyoo.Common/Models/Resources/Show.cs | 2 +- Kyoo.CommonAPI/LocalRepository.cs | 12 +++++------- Kyoo/Tasks/Crawler.cs | 23 ++++++++++------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Kyoo.Common/Models/Resources/Show.cs b/Kyoo.Common/Models/Resources/Show.cs index 3ecd8c5e..71ebfe68 100644 --- a/Kyoo.Common/Models/Resources/Show.cs +++ b/Kyoo.Common/Models/Resources/Show.cs @@ -24,7 +24,7 @@ namespace Kyoo.Models public bool IsMovie { get; set; } - public virtual IEnumerable ExternalIDs { get; set; } + [EditableRelation] public virtual IEnumerable ExternalIDs { get; set; } [JsonIgnore] public int? StudioID { get; set; } diff --git a/Kyoo.CommonAPI/LocalRepository.cs b/Kyoo.CommonAPI/LocalRepository.cs index 871f3cf5..4bd1a604 100644 --- a/Kyoo.CommonAPI/LocalRepository.cs +++ b/Kyoo.CommonAPI/LocalRepository.cs @@ -159,17 +159,15 @@ namespace Kyoo.Controllers if (old == null) throw new ItemNotFound($"No resource found with the ID {edited.ID}."); - - IEnumerable relations = Database.Entry(old).Collections - .Concat(Database.Entry(old).Navigations); - foreach (NavigationEntry navigation in relations) - if (navigation.Metadata.PropertyInfo.GetCustomAttribute() != null) - await navigation.LoadAsync(); + foreach (NavigationEntry navigation in Database.Entry(old).Navigations) + if (navigation.Metadata.PropertyInfo.GetCustomAttribute() != null + && navigation.Metadata.GetGetter().GetClrValue(edited) != default) + await navigation.LoadAsync(); + if (resetOld) Utility.Nullify(old); Utility.Complete(old, edited); - // TODO Validation set values & setting values trigger a change round in the OEM. A change round should only be triggered if the item is actually different. await Validate(old); await Database.SaveChangesAsync(); return old; diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index 9fefdb54..48820e67 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -8,7 +8,6 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Kyoo.Models.Exceptions; -using Kyoo.Models.Watch; using Microsoft.Extensions.DependencyInjection; namespace Kyoo.Controllers @@ -121,18 +120,16 @@ namespace Kyoo.Controllers .Where(x => IsVideo(x) && episodes.All(y => y.Path != x)) .GroupBy(Path.GetDirectoryName) .ToList(); - - IEnumerable tasks = shows - .Select(x => x.First()) - .Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken)); - foreach (Task[] showTasks in tasks.BatchBy(_parallelTasks)) - await Task.WhenAll(showTasks); - tasks = shows - .SelectMany(x => x.Skip(1)) - .Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken)); - foreach (Task[] episodeTasks in tasks.BatchBy(_parallelTasks * 2)) - await Task.WhenAll(episodeTasks); + IEnumerable tasks = shows.Select(x => x.First()); + foreach (string[] showTasks in tasks.BatchBy(_parallelTasks)) + await Task.WhenAll(showTasks + .Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))); + + tasks = shows.SelectMany(x => x.Skip(1)); + foreach (string[] episodeTasks in tasks.BatchBy(_parallelTasks * 2)) + await Task.WhenAll(episodeTasks + .Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))); } } @@ -233,7 +230,7 @@ namespace Kyoo.Controllers try { - await libraryManager.RegisterShow(show); + show = await libraryManager.RegisterShow(show); } catch (DuplicatedItemException) {