From 0b486cdc08ddc93c94e29de309e25c860452c79c Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Mon, 4 Jan 2021 13:10:19 -0600 Subject: [PATCH] Scan library after we edit library folders, only if folders have differences. --- API/Controllers/LibraryController.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs index aba75d760..3b0481866 100644 --- a/API/Controllers/LibraryController.cs +++ b/API/Controllers/LibraryController.cs @@ -159,14 +159,24 @@ namespace API.Controllers public async Task UpdateLibrary(UpdateLibraryDto libraryForUserDto) { var library = await _libraryRepository.GetLibraryForIdAsync(libraryForUserDto.Id); + + var originalFolders = library.Folders.Select(x => x.Path); + var differenceBetweenFolders = originalFolders.Except(libraryForUserDto.Folders); + library.Name = libraryForUserDto.Name; library.Folders = libraryForUserDto.Folders.Select(s => new FolderPath() {Path = s}).ToList(); + + _libraryRepository.Update(library); if (await _libraryRepository.SaveAllAsync()) { - // TODO: We should probably call ScanLibrary after this + if (differenceBetweenFolders.Any()) + { + BackgroundJob.Enqueue(() => _directoryService.ScanLibrary(library.Id)); + } + return Ok(); }