< Summary

Information
Class: Anichron.Worker.Ingestion.Classification.FileClassification
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: 3
Uncovered lines: 0
Coverable lines: 3
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
get_Row()100%22100%
get_DefersToAnotherRow()100%44100%
get_TakesContent()100%44100%

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
 41235    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>
 48138    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
 8242        => Outcome is FileOutcome.ContentChanged or FileOutcome.AutoRestoredContentChanged or FileOutcome.OverwrittenByM
 43}
 44
 45internal sealed record IngestionClassification(
 46    FileClassification Primary,
 47    FileClassification? Secondary,
 48    PairingAction Pairing)
 49{
 50    public bool NeedsProcessing
 51        => 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
 58        => Halves.Any(file => file.Outcome == FileOutcome.OverwrittenByMove)
 59            ? [.. Halves.Select(file => file.Retired).OfType<MediaAsset>()]
 60            : [];
 61
 62    private IEnumerable<FileClassification> Halves => Secondary is null ? [Primary] : [Primary, Secondary];
 63
 64    public int DuplicateCopies => NeedsProcessing
 65        ? 0
 66        : new[] { Primary, Secondary }.Count(file => file?.Outcome is FileOutcome.DuplicateCopy or FileOutcome.Overwritt
 67}