< Summary

Information
Class: Anichron.Worker.Ingestion.Pipeline.IngestionContext
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Pipeline/IngestionContext.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 103
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
StageSoftDeleted()100%11100%
StageAutoRestored()100%11100%
CommitCounts()100%11100%
get_ProxyFiles()100%11100%
ProxyFilesOf(...)100%11100%
get_CreatedProxyFiles()100%11100%
AddProxyFile(...)100%22100%
ReleaseProxyFiles(...)100%11100%
StageMovProxies(...)100%11100%
ReleaseStagedMovProxies()100%22100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Pipeline/IngestionContext.cs

#LineLine coverage
 1using Anichron.Core.Domain;
 2using Anichron.Worker.Ingestion.Classification;
 3using Anichron.Worker.Ingestion.Extraction;
 4
 5namespace Anichron.Worker.Ingestion.Pipeline;
 6
 7internal sealed class IngestionContext
 8{
 5339    private readonly List<ProxyFile> proxyFiles = [];
 53310    private readonly HashSet<ProxyFile> replacedFiles = [];
 53311    private readonly Lock proxyFilesLock = new();
 53312    private readonly HashSet<Guid> stagedMovs = [];
 13
 14    public required IngestionItem Item { get; init; }
 15    public required UserStorageConfig Config { get; init; }
 16
 17    public required Guid AttemptId { get; init; }
 18
 19    public Guid AssetId { get; set; }
 20
 21    public string? ContentHash { get; set; }
 22    public string? SecondaryHash { get; set; }
 23    public IngestionClassification? Classification { get; set; }
 24    public ExtractedMedia? Extracted { get; set; }
 25    public string? Blurhash { get; set; }
 26    public MediaAsset? Asset { get; set; }
 27
 28    /// <summary>Rows this item soft-deleted, counted once the save that soft-deleted them succeeded.</summary>
 29    public int SoftDeleted { get; private set; }
 30
 31    /// <summary>Soft-deleted rows this item made active again, counted once the save that restored them succeeded.</sum
 32    public int AutoRestored { get; private set; }
 33
 34    /// <summary>Rows soft-deleted on tracked entities, not saved yet.</summary>
 35    public int StagedSoftDeleted { get; private set; }
 36
 37    /// <summary>Rows made active again on tracked entities, not saved yet.</summary>
 38    public int StagedAutoRestored { get; private set; }
 39
 5340    public void StageSoftDeleted() => StagedSoftDeleted++;
 41
 2642    public void StageAutoRestored() => StagedAutoRestored++;
 43
 44    /// <summary>Counts the staged changes, once a save has persisted them.</summary>
 45    public void CommitCounts()
 11746    {
 11747        (SoftDeleted, AutoRestored) = (SoftDeleted + StagedSoftDeleted, AutoRestored + StagedAutoRestored);
 11748        (StagedSoftDeleted, StagedAutoRestored) = (0, 0);
 11749    }
 50
 51    // Image proxies register concurrently.
 52    public IReadOnlyList<ProxyFile> ProxyFiles
 53    {
 54        get
 5055        {
 56            lock (proxyFilesLock)
 5057                return [.. proxyFiles];
 5058        }
 59    }
 60
 61    public IReadOnlyList<ProxyFile> ProxyFilesOf(Guid ownerAssetId)
 13862    {
 63        lock (proxyFilesLock)
 13864            return [.. proxyFiles.Where(proxy => proxy.AssetId == ownerAssetId)];
 13865    }
 66
 67    /// <summary>The registered proxies whose final file did not exist before this attempt wrote it.</summary>
 68    public IReadOnlyList<ProxyFile> CreatedProxyFiles
 69    {
 70        get
 3671        {
 72            lock (proxyFilesLock)
 3673                return [.. proxyFiles.Where(proxy => !replacedFiles.Contains(proxy))];
 3674        }
 75    }
 76
 77    public void AddProxyFile(ProxyFile proxyFile, bool replacedExistingFile = false)
 25378    {
 79        lock (proxyFilesLock)
 25380        {
 25381            proxyFiles.Add(proxyFile);
 25382            if (replacedExistingFile)
 283                replacedFiles.Add(proxyFile);
 25384        }
 25385    }
 86
 87    public void ReleaseProxyFiles(Guid ownerAssetId)
 3488    {
 89        lock (proxyFilesLock)
 3490            proxyFiles.RemoveAll(proxy => proxy.AssetId == ownerAssetId);
 3491    }
 92
 93    /// <summary>Notes a video whose registered proxies the item's save hands to the database.</summary>
 94    /// <param name="movId">The video that owns the proxies.</param>
 4895    public void StageMovProxies(Guid movId) => stagedMovs.Add(movId);
 96
 97    /// <summary>Releases the proxies of every staged video, so compensation leaves them in place.</summary>
 98    public void ReleaseStagedMovProxies()
 11799    {
 417100        foreach (var movId in stagedMovs)
 33101            ReleaseProxyFiles(movId);
 117102    }
 103}