< Summary

Information
Class: Anichron.Worker.Ingestion.Classification.IngestionClassification
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Classification/IngestionClassification.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 67
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%
get_NeedsProcessing()100%44100%
get_RetiredFirst()100%22100%
get_Halves()100%22100%
get_DuplicateCopies()100%22100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Classification/IngestionClassification.cs

#LineLine coverage
 1using Anichron.Core.Domain;
 2
 3namespace Anichron.Worker.Ingestion.Classification;
 4
 5internal enum FileOutcome
 6{
 7    New = 0,
 8    Unchanged = 1,
 9    Moved = 2,
 10    DuplicateCopy = 3,
 11    ContentChanged = 5,
 12    OverwrittenByCopy = 6,
 13    OverwrittenByMove = 7,
 14    AutoRestored = 8,
 15    AutoRestoredMoved = 9,
 16    AutoRestoredContentChanged = 10,
 17    LoneLivePhotoVideo = 11,
 18}
 19
 20internal enum PairingAction
 21{
 22    None = 0,
 23    AttachMov = 1,
 24    BackfillMovProxy = 2,
 25    PointAtMov = 3,
 26}
 27
 28/// <summary>What one crawled file is, and the stored rows its outcome acts on.</summary>
 29/// <param name="Outcome">What the crawled file is.</param>
 30/// <param name="Stored">The row the outcome acts on.</param>
 31/// <param name="Retired">The row the outcome soft-deletes.</param>
 32internal sealed record FileClassification(FileOutcome Outcome, MediaAsset? Stored, MediaAsset? Retired = null)
 33{
 34    /// <summary>The row that describes the file at its path once the outcome is applied; null when the file is new or a
 35    public MediaAsset? Row => DefersToAnotherRow ? null : Stored;
 36
 37    /// <summary>Whether the file holds content another row keeps, so it has no row of its own.</summary>
 38    public bool DefersToAnotherRow => Outcome is FileOutcome.DuplicateCopy or FileOutcome.OverwrittenByCopy or FileOutco
 39
 40    /// <summary>Whether <see cref="Stored"/> takes content it does not hold yet.</summary>
 41    public bool TakesContent
 42        => Outcome is FileOutcome.ContentChanged or FileOutcome.AutoRestoredContentChanged or FileOutcome.OverwrittenByM
 43}
 44
 27745internal sealed record IngestionClassification(
 27746    FileClassification Primary,
 27747    FileClassification? Secondary,
 27748    PairingAction Pairing)
 49{
 50    public bool NeedsProcessing
 12951        => Primary.Outcome is FileOutcome.New or FileOutcome.ContentChanged or FileOutcome.AutoRestoredContentChanged;
 52
 53    /// <summary>
 54    /// The rows soft-deleted before the item's save, so another row can take their content: every half's retired
 55    /// row once either half was overwritten by a move, otherwise none.
 56    /// </summary>
 57    public IReadOnlyList<MediaAsset> RetiredFirst
 13458        => Halves.Any(file => file.Outcome == FileOutcome.OverwrittenByMove)
 13459            ? [.. Halves.Select(file => file.Retired).OfType<MediaAsset>()]
 13460            : [];
 61
 15762    private IEnumerable<FileClassification> Halves => Secondary is null ? [Primary] : [Primary, Secondary];
 63
 3464    public int DuplicateCopies => NeedsProcessing
 3465        ? 0
 3466        : new[] { Primary, Secondary }.Count(file => file?.Outcome is FileOutcome.DuplicateCopy or FileOutcome.Overwritt
 67}