refactor: add diagnostic logging and modernize collection expressions
- Add Debug.WriteLine to VaultStorageService empty catch blocks for diagnostics - Replace .ToList() with collection expressions [..] in fragment repositories - Remove redundant comments in DatabaseSessionService and VaultStorageService Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
parent
7865e3bc8b
commit
ef22683b70
@ -11,7 +11,7 @@ public class InMemoryFragmentRepository : IFragmentRepository
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _store.ToList();
|
||||
return [.. _store];
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ public class InMemoryFragmentRepository : IFragmentRepository
|
||||
if (string.IsNullOrWhiteSpace(q)) return [];
|
||||
lock (_lock)
|
||||
{
|
||||
return _store.Where(f => f.Tags?.Any(t => !string.IsNullOrWhiteSpace(t) && t.Contains(q, StringComparison.OrdinalIgnoreCase)) == true).ToList();
|
||||
return [.. _store.Where(f => f.Tags?.Any(t => !string.IsNullOrWhiteSpace(t) && t.Contains(q, StringComparison.OrdinalIgnoreCase)) == true)];
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public class InMemoryFragmentRepository : IFragmentRepository
|
||||
if (string.IsNullOrWhiteSpace(q)) return [];
|
||||
lock (_lock)
|
||||
{
|
||||
return _store.Where(f => !string.IsNullOrWhiteSpace(f.Type) && f.Type.Trim().Contains(q, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
return [.. _store.Where(f => !string.IsNullOrWhiteSpace(f.Type) && f.Type.Trim().Contains(q, StringComparison.OrdinalIgnoreCase))];
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ public class InMemoryFragmentRepository : IFragmentRepository
|
||||
if (timeAfter.HasValue)
|
||||
results = results.Where(f => f.Time > timeAfter.Value);
|
||||
|
||||
return results.ToList();
|
||||
return [.. results];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,9 +82,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) :
|
||||
|
||||
var conn = _session.GetConnection();
|
||||
var all = ReadAllFragments(conn);
|
||||
return all
|
||||
.Where(f => f.Tags.Any(t => t.Contains(q, StringComparison.OrdinalIgnoreCase)))
|
||||
.ToList();
|
||||
return [.. all.Where(f => f.Tags.Any(t => t.Contains(q, StringComparison.OrdinalIgnoreCase)))];
|
||||
}
|
||||
|
||||
public List<Fragment> GetByType(string type)
|
||||
@ -95,9 +93,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) :
|
||||
|
||||
var conn = _session.GetConnection();
|
||||
var all = ReadAllFragments(conn);
|
||||
return all
|
||||
.Where(f => f.Type.Contains(q, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
return [.. all.Where(f => f.Type.Contains(q, StringComparison.OrdinalIgnoreCase))];
|
||||
}
|
||||
|
||||
public List<Fragment> Search(string? type = null, string? tag = null, DateTimeOffset? timeAfter = null)
|
||||
@ -115,7 +111,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) :
|
||||
if (timeAfter.HasValue)
|
||||
results = results.Where(f => f.Time > timeAfter.Value);
|
||||
|
||||
return results.ToList();
|
||||
return [.. results];
|
||||
}
|
||||
|
||||
// ── Private helpers ──────────────────────────────────────────────
|
||||
|
||||
@ -25,7 +25,6 @@ public sealed class DatabaseSessionService(IJournalDatabaseService database) : I
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
// If password or directory changed, close the old connection
|
||||
if (_connection is not null &&
|
||||
(_password != password || _dataDirectory != dataDirectory))
|
||||
{
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
@ -42,9 +43,9 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ
|
||||
{
|
||||
File.Delete(vaultFile);
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Legacy file cleanup should never block loading.
|
||||
Debug.WriteLine($"[VaultStorageService] Failed to delete legacy vault file {fileName}: {ex.Message}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -59,11 +60,11 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
// Wrong password for this vault file; continue trying others.
|
||||
Debug.WriteLine($"[VaultStorageService] Decryption failed for {fileName} (likely wrong password)");
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Non-password vault read/decrypt/extract error; continue loading others.
|
||||
Debug.WriteLine($"[VaultStorageService] Failed to load vault {fileName}: {ex.GetType().Name} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +178,6 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ
|
||||
}
|
||||
}
|
||||
|
||||
// Final attempt should throw with the underlying exception if deletion still fails.
|
||||
Directory.Delete(dataDirectory, recursive: true);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user