< Summary

Information
Class: Anichron.Core.Data.Repository.EfProxyOrphanReader
Assembly: Anichron.Core
File(s): /home/runner/work/anichron/anichron/src/Anichron.Core/Data/Repository/ProxyOrphanReader.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 91
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ListAsync()100%1010100%
FindAsync()100%11100%
PendingConfigsAsync()100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Core/Data/Repository/ProxyOrphanReader.cs

#LineLine coverage
 1using Anichron.Core.Domain;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace Anichron.Core.Data.Repository;
 5
 6public sealed record ProxyOrphanView(
 7    Guid Id,
 8    string ProxyPath,
 9    Guid? StorageConfigId,
 10    long SizeBytes,
 11    Instant LastWriteTime,
 12    ProxyDeletionOutcome? DeletionOutcome,
 13    Instant? ProcessedAt);
 14
 15/// <summary>Which orphans of a sweep to page through.</summary>
 16/// <param name="SweepId">The sweep.</param>
 17/// <param name="Outcome">Only orphans a deletion gave this outcome, or null for any.</param>
 18/// <param name="Pending">Only orphans no deletion processed yet.</param>
 19/// <param name="StorageConfigId">Only orphans of this storage config, or null for any.</param>
 20/// <param name="Skip">Orphans before the page.</param>
 21/// <param name="Take">The page size.</param>
 22public sealed record ProxyOrphanQuery(Guid SweepId, ProxyDeletionOutcome? Outcome, bool Pending, Guid? StorageConfigId, 
 23
 24public sealed record ProxyOrphanPage(IReadOnlyList<ProxyOrphanView> Items, int Total);
 25
 26/// <summary>An orphan's id and the live storage config its directory names.</summary>
 27/// <param name="Id">The orphan.</param>
 28/// <param name="LiveStorageConfigId">The config, or null when its path names none or the config no longer exists.</para
 29public sealed record ProxyOrphanScope(Guid Id, Guid? LiveStorageConfigId);
 30
 31public interface IProxyOrphanReader
 32{
 33    /// <summary>A page of a sweep's orphans, by path.</summary>
 34    /// <param name="query">The sweep, the optional outcome and config filters, and the page.</param>
 35    /// <param name="ct">Cancels the read.</param>
 36    /// <returns>The page, and the number of orphans matching the filters.</returns>
 37    Task<ProxyOrphanPage> ListAsync(ProxyOrphanQuery query, CancellationToken ct);
 38
 39    /// <summary>The orphans of a sweep among the ids; ids that are not orphans of it are left out.</summary>
 40    /// <param name="sweepId">The sweep.</param>
 41    /// <param name="ids">The orphans asked for.</param>
 42    /// <param name="ct">Cancels the read.</param>
 43    Task<IReadOnlyList<ProxyOrphanScope>> FindAsync(Guid sweepId, IReadOnlyCollection<Guid> ids, CancellationToken ct);
 44
 45    /// <summary>Each live storage config, null for none, that a sweep's unprocessed orphans name.</summary>
 46    /// <param name="sweepId">The sweep.</param>
 47    /// <param name="ct">Cancels the read.</param>
 48    Task<IReadOnlyList<Guid?>> PendingConfigsAsync(Guid sweepId, CancellationToken ct);
 49}
 50
 651public sealed class EfProxyOrphanReader(AnichronDbContext db) : IProxyOrphanReader
 52{
 53    public async Task<ProxyOrphanPage> ListAsync(ProxyOrphanQuery query, CancellationToken ct)
 454    {
 455        var matching = db.ProxyOrphans.Where(o => o.SweepId == query.SweepId);
 456        if (query.Outcome is { } outcome)
 157            matching = matching.Where(o => o.DeletionOutcome == outcome);
 458        if (query.Pending)
 159            matching = matching.Where(o => o.DeletionOutcome == null);
 460        if (query.StorageConfigId is { } configId)
 161            matching = matching.Where(o => o.StorageConfigId == configId);
 62
 463        var items = await matching
 464            .OrderBy(o => o.ProxyPath)
 465            .Skip(query.Skip)
 466            .Take(query.Take)
 467            .Select(o => new ProxyOrphanView(
 468                o.Id, o.ProxyPath, o.StorageConfigId, o.SizeBytes, o.LastWriteTime, o.DeletionOutcome, o.ProcessedAt))
 469            .ToListAsync(ct);
 470        return new ProxyOrphanPage(items, await matching.CountAsync(ct));
 471    }
 72
 73    public async Task<IReadOnlyList<ProxyOrphanScope>> FindAsync(Guid sweepId, IReadOnlyCollection<Guid> ids, Cancellati
 174    {
 175        var live = db.StorageConfigs.LiveIds();
 176        return await db.ProxyOrphans
 177            .Where(o => o.SweepId == sweepId && ids.Contains(o.Id))
 178            .Select(o => new ProxyOrphanScope(o.Id, live.Contains(o.StorageConfigId) ? o.StorageConfigId : null))
 179            .ToListAsync(ct);
 180    }
 81
 82    public async Task<IReadOnlyList<Guid?>> PendingConfigsAsync(Guid sweepId, CancellationToken ct)
 183    {
 184        var live = db.StorageConfigs.LiveIds();
 185        return await db.ProxyOrphans
 186            .Where(o => o.SweepId == sweepId && o.DeletionOutcome == null)
 187            .Select(o => live.Contains(o.StorageConfigId) ? o.StorageConfigId : null)
 188            .Distinct()
 189            .ToListAsync(ct);
 190    }
 91}