logging adjustments etc
This commit is contained in:
		| @@ -60,17 +60,21 @@ public sealed class FileCacheManager : IHostedService | |||||||
|  |  | ||||||
|     public List<FileCacheEntity> GetAllFileCaches() => _fileCaches.Values.SelectMany(v => v).ToList(); |     public List<FileCacheEntity> GetAllFileCaches() => _fileCaches.Values.SelectMany(v => v).ToList(); | ||||||
|  |  | ||||||
|     public List<FileCacheEntity> GetAllFileCachesByHash(string hash) |     public List<FileCacheEntity> GetAllFileCachesByHash(string hash, bool ignoreCacheEntries = false, bool validate = true) | ||||||
|     { |     { | ||||||
|         List<FileCacheEntity> output = []; |         List<FileCacheEntity> output = []; | ||||||
|         if (_fileCaches.TryGetValue(hash, out var fileCacheEntities)) |         if (_fileCaches.TryGetValue(hash, out var fileCacheEntities)) | ||||||
|         { |         { | ||||||
|             foreach (var fileCache in fileCacheEntities.ToList()) |             foreach (var fileCache in fileCacheEntities.Where(c => ignoreCacheEntries ? !c.IsCacheEntry : true).ToList()) | ||||||
|  |             { | ||||||
|  |                 if (!validate) output.Add(fileCache); | ||||||
|  |                 else | ||||||
|                 { |                 { | ||||||
|                     var validated = GetValidatedFileCache(fileCache); |                     var validated = GetValidatedFileCache(fileCache); | ||||||
|                     if (validated != null) output.Add(validated); |                     if (validated != null) output.Add(validated); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return output; |         return output; | ||||||
|     } |     } | ||||||
| @@ -188,11 +192,6 @@ public sealed class FileCacheManager : IHostedService | |||||||
|                     .Replace("\\\\", "\\", StringComparison.Ordinal), |                     .Replace("\\\\", "\\", StringComparison.Ordinal), | ||||||
|                 StringComparer.OrdinalIgnoreCase); |                 StringComparer.OrdinalIgnoreCase); | ||||||
|  |  | ||||||
|             foreach (var entry in cleanedPaths) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("Getting FileCache by Cleaned Path: {path}", entry.Value); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase); |             Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase); | ||||||
|  |  | ||||||
|             var dict = _fileCaches.SelectMany(f => f.Value) |             var dict = _fileCaches.SelectMany(f => f.Value) | ||||||
| @@ -200,7 +199,7 @@ public sealed class FileCacheManager : IHostedService | |||||||
|  |  | ||||||
|             foreach (var entry in cleanedPaths) |             foreach (var entry in cleanedPaths) | ||||||
|             { |             { | ||||||
|                 _logger.LogDebug("Validating {path}", entry.Value); |                 _logger.LogDebug("Checking {path}", entry.Value); | ||||||
|  |  | ||||||
|                 if (dict.TryGetValue(entry.Value, out var entity)) |                 if (dict.TryGetValue(entry.Value, out var entity)) | ||||||
|                 { |                 { | ||||||
| @@ -229,7 +228,7 @@ public sealed class FileCacheManager : IHostedService | |||||||
|         if (_fileCaches.TryGetValue(hash, out var caches)) |         if (_fileCaches.TryGetValue(hash, out var caches)) | ||||||
|         { |         { | ||||||
|             var removedCount = caches?.RemoveAll(c => string.Equals(c.PrefixedFilePath, prefixedFilePath, StringComparison.Ordinal)); |             var removedCount = caches?.RemoveAll(c => string.Equals(c.PrefixedFilePath, prefixedFilePath, StringComparison.Ordinal)); | ||||||
|             _logger.LogDebug("Removed {count} files with hash {hash} and file cache {path}", removedCount, hash, prefixedFilePath); |             _logger.LogTrace("Removed from DB: {count} file(s) with hash {hash} and file cache {path}", removedCount, hash, prefixedFilePath); | ||||||
|  |  | ||||||
|             if (caches?.Count == 0) |             if (caches?.Count == 0) | ||||||
|             { |             { | ||||||
| @@ -308,7 +307,7 @@ public sealed class FileCacheManager : IHostedService | |||||||
|             var newHashedEntity = new FileCacheEntity(fileCache.Hash, fileCache.PrefixedFilePath + "." + ext, DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture)); |             var newHashedEntity = new FileCacheEntity(fileCache.Hash, fileCache.PrefixedFilePath + "." + ext, DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture)); | ||||||
|             newHashedEntity.SetResolvedFilePath(extensionPath); |             newHashedEntity.SetResolvedFilePath(extensionPath); | ||||||
|             AddHashedFile(newHashedEntity); |             AddHashedFile(newHashedEntity); | ||||||
|             _logger.LogDebug("Migrated from {oldPath} to {newPath}", fileCache.ResolvedFilepath, newHashedEntity.ResolvedFilepath); |             _logger.LogTrace("Migrated from {oldPath} to {newPath}", fileCache.ResolvedFilepath, newHashedEntity.ResolvedFilepath); | ||||||
|             return newHashedEntity; |             return newHashedEntity; | ||||||
|         } |         } | ||||||
|         catch (Exception ex) |         catch (Exception ex) | ||||||
| @@ -328,6 +327,7 @@ public sealed class FileCacheManager : IHostedService | |||||||
|  |  | ||||||
|         if (!entries.Exists(u => string.Equals(u.PrefixedFilePath, fileCache.PrefixedFilePath, StringComparison.OrdinalIgnoreCase))) |         if (!entries.Exists(u => string.Equals(u.PrefixedFilePath, fileCache.PrefixedFilePath, StringComparison.OrdinalIgnoreCase))) | ||||||
|         { |         { | ||||||
|  |             _logger.LogTrace("Adding to DB: {hash} => {path}", fileCache.Hash, fileCache.PrefixedFilePath); | ||||||
|             entries.Add(fileCache); |             entries.Add(fileCache); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -343,13 +343,14 @@ public sealed class FileCacheManager : IHostedService | |||||||
|             File.AppendAllLines(_csvPath, new[] { entity.CsvEntry }); |             File.AppendAllLines(_csvPath, new[] { entity.CsvEntry }); | ||||||
|         } |         } | ||||||
|         var result = GetFileCacheByPath(fileInfo.FullName); |         var result = GetFileCacheByPath(fileInfo.FullName); | ||||||
|         _logger.LogDebug("Creating cache entity for {name} success: {success}", fileInfo.FullName, (result != null)); |         _logger.LogTrace("Creating cache entity for {name} success: {success}", fileInfo.FullName, (result != null)); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private FileCacheEntity? GetValidatedFileCache(FileCacheEntity fileCache) |     private FileCacheEntity? GetValidatedFileCache(FileCacheEntity fileCache) | ||||||
|     { |     { | ||||||
|         var resultingFileCache = ReplacePathPrefixes(fileCache); |         var resultingFileCache = ReplacePathPrefixes(fileCache); | ||||||
|  |         _logger.LogTrace("Validating {path}", fileCache.PrefixedFilePath); | ||||||
|         resultingFileCache = Validate(resultingFileCache); |         resultingFileCache = Validate(resultingFileCache); | ||||||
|         return resultingFileCache; |         return resultingFileCache; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -98,7 +98,7 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable | |||||||
|             Dictionary<string, FileDataEntry> data = new(StringComparer.OrdinalIgnoreCase); |             Dictionary<string, FileDataEntry> data = new(StringComparer.OrdinalIgnoreCase); | ||||||
|             foreach (var fileEntry in obj.Value) |             foreach (var fileEntry in obj.Value) | ||||||
|             { |             { | ||||||
|                 var fileCacheEntries = _fileCacheManager.GetAllFileCachesByHash(fileEntry.Hash).Where(c => !c.IsCacheEntry).ToList(); |                 var fileCacheEntries = _fileCacheManager.GetAllFileCachesByHash(fileEntry.Hash, ignoreCacheEntries: true, validate: false).ToList(); | ||||||
|                 if (fileCacheEntries.Count == 0) continue; |                 if (fileCacheEntries.Count == 0) continue; | ||||||
|  |  | ||||||
|                 var filePath = fileCacheEntries[0].ResolvedFilepath; |                 var filePath = fileCacheEntries[0].ResolvedFilepath; | ||||||
| @@ -183,7 +183,7 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable | |||||||
|         { |         { | ||||||
|             var compressedsize = await fileCacheManager.GetCompressedFileLength(Hash, token).ConfigureAwait(false); |             var compressedsize = await fileCacheManager.GetCompressedFileLength(Hash, token).ConfigureAwait(false); | ||||||
|             var normalSize = new FileInfo(FilePaths[0]).Length; |             var normalSize = new FileInfo(FilePaths[0]).Length; | ||||||
|             var entries = fileCacheManager.GetAllFileCachesByHash(Hash); |             var entries = fileCacheManager.GetAllFileCachesByHash(Hash, ignoreCacheEntries: true, validate: false); | ||||||
|             foreach (var entry in entries) |             foreach (var entry in entries) | ||||||
|             { |             { | ||||||
|                 entry.Size = normalSize; |                 entry.Size = normalSize; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 rootdarkarchon
					rootdarkarchon