From 5b5c1e758f0f6ce61c44a5e17d3ef8f6fb63354c Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Wed, 10 Feb 2021 12:36:25 -0600 Subject: [PATCH] Small performance enhancement on fetching library only once. --- API/Services/ScannerService.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/API/Services/ScannerService.cs b/API/Services/ScannerService.cs index 83a2bf6d7..6766c97de 100644 --- a/API/Services/ScannerService.cs +++ b/API/Services/ScannerService.cs @@ -74,9 +74,8 @@ namespace API.Services Cleanup(); Library library; try - { - // TODO: Use expensive library lookup here and pass to UpdateLibrary so we aren't querying twice - library = Task.Run(() => _unitOfWork.LibraryRepository.GetLibraryForIdAsync(libraryId)).Result; + { + library = Task.Run(() => _unitOfWork.LibraryRepository.GetFullLibraryForIdAsync(libraryId)).Result; } catch (Exception ex) { @@ -130,7 +129,7 @@ namespace API.Services var filtered = _scannedSeries.Where(kvp => kvp.Value.Count != 0); var series = filtered.ToDictionary(v => v.Key, v => v.Value); - UpdateLibrary(libraryId, series); + UpdateLibrary(library, series); _unitOfWork.LibraryRepository.Update(library); if (Task.Run(() => _unitOfWork.Complete()).Result) @@ -146,10 +145,9 @@ namespace API.Services _logger.LogInformation("Processed {TotalFiles} files in {ElapsedScanTime} milliseconds for {LibraryName}", totalFiles, sw.ElapsedMilliseconds + scanElapsedTime, library.Name); } - private void UpdateLibrary(int libraryId, Dictionary> parsedSeries) + private void UpdateLibrary(Library library, Dictionary> parsedSeries) { - var library = Task.Run(() => _unitOfWork.LibraryRepository.GetFullLibraryForIdAsync(libraryId)).Result; - + // TODO: Split this into multiple threads // First, remove any series that are not in parsedSeries list var foundSeries = parsedSeries.Select(s => Parser.Parser.Normalize(s.Key)).ToList(); var missingSeries = library.Series.Where(existingSeries =>