diff --git a/PiwigoDirectorySync/Services/FileIndexer.cs b/PiwigoDirectorySync/Services/FileIndexer.cs index 47fa4ab..1d57fa3 100644 --- a/PiwigoDirectorySync/Services/FileIndexer.cs +++ b/PiwigoDirectorySync/Services/FileIndexer.cs @@ -48,7 +48,7 @@ internal class FileIndexer : IFileIndexer return; } - _logger.Information("Indexing file {FullFilePath}", fullFilePath); + _logger.Debug("Indexing file {FullFilePath}", fullFilePath); var fileInfo = new FileInfo(fullFilePath); if (!fileInfo.Exists) @@ -88,21 +88,25 @@ internal class FileIndexer : IFileIndexer } } - private static async Task GetOrAddImageAsync(PersistenceContext db, int albumId, string relativePath, CancellationToken ct) + private async Task GetOrAddImageAsync(PersistenceContext db, int albumId, string relativePath, CancellationToken ct) { var imageEntity = await db.PiwigoImages.Where(i => i.AlbumId == albumId && i.FilePath == relativePath).FirstOrDefaultAsync(ct); - if (imageEntity is null) + if (imageEntity is not null) { - imageEntity = new ImageEntity - { - AlbumId = albumId, - FilePath = relativePath, - UploadRequired = true, - DeleteRequired = false - }; - db.PiwigoImages.Add(imageEntity); + _logger.Debug("Found file {RelativePath}", relativePath); + return imageEntity; } + _logger.Information("Adding new file {RelativePath}", relativePath); + imageEntity = new ImageEntity + { + AlbumId = albumId, + FilePath = relativePath, + UploadRequired = true, + DeleteRequired = false + }; + db.PiwigoImages.Add(imageEntity); + return imageEntity; }