From f39b2ae3fe5dec056ddbb8bf60d3f46bbfec713d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Sat, 30 Sep 2023 15:28:21 +0200 Subject: [PATCH] little scanner optimization --- PiwigoDirectorySync/Services/FileSystemScanner.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/PiwigoDirectorySync/Services/FileSystemScanner.cs b/PiwigoDirectorySync/Services/FileSystemScanner.cs index e9b59e6..5dfa4a4 100644 --- a/PiwigoDirectorySync/Services/FileSystemScanner.cs +++ b/PiwigoDirectorySync/Services/FileSystemScanner.cs @@ -45,17 +45,8 @@ internal class FileSystemScanner : IFileSystemScanner { _logger.Information("Scanning directory {DirectoryFullName} for images", directory.FullName); - var imageFiles = AppSettings.SupportedExtensions.SelectMany(ext => directory.GetFiles($"*.{ext}", SearchOption.TopDirectoryOnly)) - .Select(f => f.FullName) - .ToHashSet(StringComparer.OrdinalIgnoreCase); - - if (!imageFiles.Any()) - { - _logger.Debug("No images in {DirectoryFullName} found, skipping", directory.FullName); - return; - } - - foreach (var imageFile in imageFiles.Select(f => new FileInfo(f))) + var imageFiles = AppSettings.SupportedExtensions.SelectMany(ext => directory.GetFiles($"*.{ext}", SearchOption.TopDirectoryOnly)); + foreach (var imageFile in imageFiles) { _logger.Debug("Found image {ImageFileFullName}, enqueue index", imageFile.FullName); await fileQueue.Writer.WriteAsync(imageFile.FullName, ct); @@ -70,7 +61,7 @@ internal class FileSystemScanner : IFileSystemScanner private static IEnumerable GetDirectories(DirectoryInfo directoryInfo) { yield return directoryInfo; - foreach (var directory in directoryInfo.EnumerateDirectories().SelectMany(GetDirectories)) + foreach (var directory in directoryInfo.EnumerateDirectories().SelectMany(GetDirectories).OrderBy(d => d.FullName)) { yield return directory; }