32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
namespace WxAgent.Core;
|
|
|
|
public sealed record AccountDatabaseEntry(string Fingerprint, string RelativePath);
|
|
|
|
/// <summary>Decides which verified keys may be reused from cache, avoiding repeated memory scans for cached accounts.</summary>
|
|
public static class KeyCachePlanner
|
|
{
|
|
public static string Key(string accountFingerprint, string relativePath) =>
|
|
$"{accountFingerprint}|{relativePath}";
|
|
|
|
public static IReadOnlySet<string> VerifiedKeys(IEnumerable<AccountKeySet> cached)
|
|
{
|
|
var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var account in cached)
|
|
foreach (var database in account.Databases)
|
|
set.Add(Key(account.AccountRootFingerprint, database.RelativePath));
|
|
return set;
|
|
}
|
|
|
|
public static bool HasPending(IEnumerable<AccountDatabaseEntry> discovered, IReadOnlySet<string> verified)
|
|
{
|
|
foreach (var entry in discovered)
|
|
{
|
|
if (!verified.Contains(Key(entry.Fingerprint, entry.RelativePath)))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |