From 51fa75214b01e9ae748dc58985d1819454b937f4 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 12 Jun 2020 03:39:00 +0200 Subject: [PATCH] Cleaning up --- Kyoo/Startup.cs | 4 ++-- Kyoo/Tasks/Crawler.cs | 24 +++++++++++------------- Kyoo/appsettings.json | 3 ++- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index bd1a5272..c16e5740 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -51,8 +51,8 @@ namespace Kyoo services.AddDbContext(options => { options.UseLazyLoadingProxies() - .UseNpgsql(_configuration.GetConnectionString("Database")); - // .EnableSensitiveDataLogging() + .UseNpgsql(_configuration.GetConnectionString("Database")) + .EnableSensitiveDataLogging(); // .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole())); }); diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index a12e777b..b5c6002f 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -67,7 +67,8 @@ namespace Kyoo.Controllers foreach (Library library in libraries) library.Providers = library.Providers; - await Task.WhenAll(libraries.Select(x => Scan(x, episodes, cancellationToken))); + await Task.WhenAll(libraries.Select(x => Scan(x, episodes, cancellationToken)).ToArray()); + Console.WriteLine("Done."); } catch (Exception ex) { @@ -79,7 +80,7 @@ namespace Kyoo.Controllers private Task Scan(Library library, IEnumerable episodes, CancellationToken cancellationToken) { Console.WriteLine($"Scanning library {library.Name} at {string.Join(", ", library.Paths)}."); - return Task.WhenAll(library.Paths.Select(async path => + return Task.WhenAll(library.Paths.Select(path => { if (cancellationToken.IsCancellationRequested) return Task.CompletedTask; @@ -91,36 +92,33 @@ namespace Kyoo.Controllers } catch (DirectoryNotFoundException) { - await Console.Error.WriteLineAsync($"The library's directory {path} could not be found (library slug: {library.Slug})"); + Console.Error.WriteLine($"The library's directory {path} could not be found (library slug: {library.Slug})"); return Task.CompletedTask; } catch (PathTooLongException) { - await Console.Error.WriteLineAsync($"The library's directory {path} is too long for this system. (library slug: {library.Slug})"); + Console.Error.WriteLine($"The library's directory {path} is too long for this system. (library slug: {library.Slug})"); return Task.CompletedTask; } catch (ArgumentException) { - await Console.Error.WriteLineAsync($"The library's directory {path} is invalid. (library slug: {library.Slug})"); + Console.Error.WriteLine($"The library's directory {path} is invalid. (library slug: {library.Slug})"); return Task.CompletedTask; } catch (UnauthorizedAccessException) { - await Console.Error.WriteLineAsync($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})"); + Console.Error.WriteLine($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})"); return Task.CompletedTask; } return Task.WhenAll(files.Select(file => - //foreach (string file in files) { if (!IsVideo(file) || episodes.Any(x => x.Path == file)) - /*continue;*/ return Task.CompletedTask; + return Task.CompletedTask; string relativePath = file.Substring(path.Length); - return /*await*/ RegisterFile(file, relativePath, library, cancellationToken); - })); - - // return Task.CompletedTask; - })); + return RegisterFile(file, relativePath, library, cancellationToken); + }).ToArray()); + }).ToArray()); } private async Task RegisterFile(string path, string relativePath, Library library, CancellationToken token) diff --git a/Kyoo/appsettings.json b/Kyoo/appsettings.json index 836b8edf..5abce11c 100644 --- a/Kyoo/appsettings.json +++ b/Kyoo/appsettings.json @@ -7,7 +7,8 @@ "LogLevel": { "Default": "Warning", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Microsoft.EntityFrameworkCore.DbUpdateException": "None" } }, "AllowedHosts": "*",