< Summary

Information
Class: Anichron.Worker.Crawling.CrawlTally
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Crawling/CrawlTally.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 55
Uncovered lines: 0
Coverable lines: 55
Total lines: 141
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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_Run()50%22100%
Found(...)100%11100%
FolderSkipped()100%11100%
LinkSkipped()100%11100%
UnsupportedSkipped()100%11100%
Walked()100%11100%
Processed(...)100%11100%
Failed()100%11100%
Update(...)100%22100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Crawling/CrawlTally.cs

#LineLine coverage
 1using Anichron.Core.Work;
 2using Anichron.Worker.Ingestion;
 3using Anichron.Worker.Ingestion.Pipeline;
 4
 5namespace Anichron.Worker.Crawling;
 6
 7/// <summary>A crawl's results summary. A Live Photo pair counts as one item.</summary>
 8/// <param name="Found">Items the walk queued for ingestion.</param>
 9/// <param name="Processed">Items handled without an error, unchanged ones included.</param>
 10/// <param name="Failed">Items whose ingestion failed.</param>
 11public sealed record CrawlResult(long Found, long Processed, long Failed)
 12{
 13    /// <summary>Processed items whose content was read: new, edited, or restored with changed content.</summary>
 14    public long Ingested { get; init; }
 15
 16    /// <summary>Files the walk reached and found no media type for; excluded folders and files are not counted.</summar
 17    public int SkippedUnsupported { get; init; }
 18
 19    /// <summary>The duplicate report for the crawled config, or null when the report failed.</summary>
 20    public DuplicateCounts? Duplicates { get; init; }
 21
 22    public ReconciliationCounts? Reconciliation { get; init; }
 23
 24    /// <summary>Links the walk skipped, to files or folders: a crawl never follows a link.</summary>
 25    public int SkippedLinks { get; init; }
 26}
 27
 28/// <summary>How a crawl brought the config's rows in line with its files.</summary>
 29/// <param name="SoftDeleted">Rows soft-deleted, while ingesting or because the walk did not find their file.</param>
 30/// <param name="AutoRestored">Soft-deleted rows made active again because the crawl found their file.</param>
 31/// <param name="SkippedBecause">Why missing files were not looked for, or null when they were.</param>
 32public sealed record ReconciliationCounts(int SoftDeleted, int AutoRestored, MissingFileSkip? SkippedBecause);
 33
 34/// <summary>What one crawl's walk and ingestion counted.</summary>
 35/// <param name="Result">The crawl's results summary, before the duplicate report.</param>
 36/// <param name="DuplicateCopies">Copies within the crawled config, counted by this crawl only.</param>
 37internal sealed record CrawlRun(CrawlResult Result, int DuplicateCopies)
 38{
 39    /// <summary>Rows soft-deleted while ingesting, because their path now holds other stored content.</summary>
 40    public int SoftDeleted { get; init; }
 41
 42    public int AutoRestored { get; init; }
 43
 44    /// <summary>Relative paths of every media file the walk queued, both halves of a Live Photo included.</summary>
 45    public IReadOnlySet<string> FoundPaths { get; init; } = new HashSet<string>(StringComparer.Ordinal);
 46
 47    /// <summary>Whether the walk read every folder under the root.</summary>
 48    public bool WalkComplete { get; init; }
 49}
 50
 4251internal sealed class CrawlTally(IWorkProgress progress)
 52{
 4253    private readonly Lock gate = new();
 4254    private readonly HashSet<string> foundPaths = new(StringComparer.Ordinal);
 55    private long found;
 56    private long processed;
 57    private long failed;
 58    private long ingested;
 59    private int duplicateCopies;
 60    private int softDeleted;
 61    private int autoRestored;
 62    private int skippedLinks;
 63    private int skippedUnsupported;
 64    private bool walked;
 65    private bool folderSkipped;
 66
 67    public CrawlRun Run
 68    {
 69        get
 3970        {
 71            lock (gate)
 3972            {
 3973                var result = new CrawlResult(found, processed, failed)
 3974                {
 3975                    Ingested = ingested,
 3976                    SkippedLinks = skippedLinks,
 3977                    SkippedUnsupported = skippedUnsupported,
 3978                };
 3979                return new CrawlRun(result, duplicateCopies)
 3980                {
 3981                    SoftDeleted = softDeleted,
 3982                    AutoRestored = autoRestored,
 3983                    FoundPaths = new HashSet<string>(foundPaths, StringComparer.Ordinal),
 3984                    WalkComplete = walked && !folderSkipped,
 3985                };
 86            }
 3987        }
 88    }
 89
 6890    public void Found(IngestionItem item) => Update(() =>
 6891    {
 6892        found++;
 6893        foundPaths.Add(item.RelativePath);
 6894        if (item.SecondaryFile is { } secondary)
 6895            foundPaths.Add(secondary.RelativePath);
 6896    });
 97
 98    public void FolderSkipped()
 299    {
 100        lock (gate)
 2101            folderSkipped = true;
 2102    }
 103
 104    public void LinkSkipped()
 5105    {
 106        lock (gate)
 5107            skippedLinks++;
 5108    }
 109
 110    public void UnsupportedSkipped()
 8111    {
 112        lock (gate)
 8113            skippedUnsupported++;
 8114    }
 115
 41116    public void Walked() => Update(() => walked = true);
 117
 52118    public void Processed(IngestionContext context) => Update(() =>
 52119    {
 52120        processed++;
 52121        if (context.Classification?.NeedsProcessing == true)
 52122            ingested++;
 52123        duplicateCopies += context.Classification?.DuplicateCopies ?? 0;
 52124        softDeleted += context.SoftDeleted;
 52125        autoRestored += context.AutoRestored;
 52126    });
 127
 12128    public void Failed() => Update(() => failed++);
 129
 130    private void Update(Action change)
 173131    {
 132        lock (gate)
 173133        {
 173134            change();
 173135            progress.Report(
 173136                processed + failed,
 173137                walked ? found : null,
 173138                $"{found} found, {processed} processed, {failed} failed");
 173139        }
 173140    }
 141}