little scanner optimization
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good

This commit is contained in:
Philipp Häfelfinger 2023-09-30 15:28:21 +02:00
parent ec6e062971
commit f39b2ae3fe

View File

@ -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<DirectoryInfo> 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;
}