logging adjustments etc

This commit is contained in:
rootdarkarchon
2024-02-15 12:30:28 +01:00
committed by Loporrit
parent c1d8599b9c
commit 80894fe446
2 changed files with 16 additions and 15 deletions

View File

@@ -60,17 +60,21 @@ public sealed class FileCacheManager : IHostedService
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 = [];
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);
if (validated != null) output.Add(validated);
}
}
}
return output;
}
@@ -188,11 +192,6 @@ public sealed class FileCacheManager : IHostedService
.Replace("\\\\", "\\", StringComparison.Ordinal),
StringComparer.OrdinalIgnoreCase);
foreach (var entry in cleanedPaths)
{
_logger.LogInformation("Getting FileCache by Cleaned Path: {path}", entry.Value);
}
Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase);
var dict = _fileCaches.SelectMany(f => f.Value)
@@ -200,7 +199,7 @@ public sealed class FileCacheManager : IHostedService
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))
{
@@ -229,7 +228,7 @@ public sealed class FileCacheManager : IHostedService
if (_fileCaches.TryGetValue(hash, out var caches))
{
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)
{
@@ -308,7 +307,7 @@ public sealed class FileCacheManager : IHostedService
var newHashedEntity = new FileCacheEntity(fileCache.Hash, fileCache.PrefixedFilePath + "." + ext, DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture));
newHashedEntity.SetResolvedFilePath(extensionPath);
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;
}
catch (Exception ex)
@@ -328,6 +327,7 @@ public sealed class FileCacheManager : IHostedService
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);
}
}
@@ -343,13 +343,14 @@ public sealed class FileCacheManager : IHostedService
File.AppendAllLines(_csvPath, new[] { entity.CsvEntry });
}
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;
}
private FileCacheEntity? GetValidatedFileCache(FileCacheEntity fileCache)
{
var resultingFileCache = ReplacePathPrefixes(fileCache);
_logger.LogTrace("Validating {path}", fileCache.PrefixedFilePath);
resultingFileCache = Validate(resultingFileCache);
return resultingFileCache;
}

View File

@@ -98,7 +98,7 @@ public sealed class CharacterAnalyzer : MediatorSubscriberBase, IDisposable
Dictionary<string, FileDataEntry> data = new(StringComparer.OrdinalIgnoreCase);
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;
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 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)
{
entry.Size = normalSize;