Scan library after we edit library folders, only if folders have differences.

This commit is contained in:
Joseph Milazzo 2021-01-04 13:10:19 -06:00
parent 219f6e675a
commit 0b486cdc08

View File

@ -159,14 +159,24 @@ namespace API.Controllers
public async Task<ActionResult> 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();
}