diff --git a/src/Lumina.Application/Common/Infrastructure/Security/IFileHashService.cs b/src/Lumina.Application/Common/Infrastructure/Security/IFileHashService.cs index d5f5a63b..b191d607 100644 --- a/src/Lumina.Application/Common/Infrastructure/Security/IFileHashService.cs +++ b/src/Lumina.Application/Common/Infrastructure/Security/IFileHashService.cs @@ -23,7 +23,7 @@ public interface IFileHashService /// Callback to invoke during processing of elements. /// Cancellation token that can be used to stop the execution. /// A collection of files that changed since last library scan, along with their hashes. - List HashFiles( + Task> HashFilesAsync( List files, Dictionary previousScanResults, Func callback, diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/HashComparerJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/HashComparerJob.cs index 7fd4c5ee..43478ace 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/HashComparerJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/HashComparerJob.cs @@ -134,8 +134,8 @@ internal sealed class HashComparerJob : MediaLibraryScanJob, IHashComparerJob lastUpdateTime = now; } } - int processedFiles = 0; - List processed = fileHashService.HashFiles(filesToHash, libraryScanResultEntities, + int processedFilesCount = 0; + List processedFiles = await fileHashService.HashFilesAsync(filesToHash, libraryScanResultEntities, async () => { // check if enough time has passed since last update @@ -144,7 +144,7 @@ internal sealed class HashComparerJob : MediaLibraryScanJob, IHashComparerJob { // increment the number of processed elements progress publishJobProgressResult = await PublishJobProgress( - publisher, compositeKey, Interlocked.Increment(ref processedFiles), files.Count, cancellationToken).ConfigureAwait(false); + publisher, compositeKey, Interlocked.Increment(ref processedFilesCount), files.Count, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) return; // update the last update time @@ -156,11 +156,11 @@ internal sealed class HashComparerJob : MediaLibraryScanJob, IHashComparerJob await publisher!.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; sw.Stop(); - Console.WriteLine($"Ended file hashing in {sw.ElapsedMilliseconds}ms, hashed {processed.Count} files."); + Console.WriteLine($"Ended file hashing in {sw.ElapsedMilliseconds}ms, hashed {processedFiles.Count} files."); // call each linked child with the obtained payload foreach (IMediaLibraryScanJob child in Children) - await child.ExecuteAsync(id, files, cancellationToken).ConfigureAwait(false); + await child.ExecuteAsync(id, processedFiles, cancellationToken).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false); } } diff --git a/src/Lumina.Infrastructure/Core/Security/FileHashService.cs b/src/Lumina.Infrastructure/Core/Security/FileHashService.cs index 2c2c049b..e8f9d53f 100644 --- a/src/Lumina.Infrastructure/Core/Security/FileHashService.cs +++ b/src/Lumina.Infrastructure/Core/Security/FileHashService.cs @@ -33,8 +33,8 @@ internal class FileHashService : IFileHashService /// Callback to invoke during processing of elements. /// Cancellation token that can be used to stop the execution. /// A collection of files that changed since last library scan, along with their hashes. - public List HashFiles( - List files, + public async Task> HashFilesAsync( + List files, Dictionary previousScanResults, Func callback, CancellationToken cancellationToken) @@ -49,7 +49,7 @@ internal class FileHashService : IFileHashService CancellationToken = cancellationToken, MaxDegreeOfParallelism = Environment.ProcessorCount }; - Parallel.ForEach(files, parallelOptions, async file => + await Parallel.ForEachAsync(files, parallelOptions, async (file, cancellationToken) => { cancellationToken.ThrowIfCancellationRequested(); try