< Summary

Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 440
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .cctor()100%11100%
File 2: .ctor(...)100%11100%
File 2: ReportAsync()100%88100%

File(s)

/home/runner/work/anichron/anichron/src/.artifacts/obj/Anichron.Worker/debug/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs

File '/home/runner/work/anichron/anichron/src/.artifacts/obj/Anichron.Worker/debug/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs' does not exist (any more).

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

#LineLine coverage
 1using Anichron.Core.Data.Repository;
 2using Anichron.Core.Domain;
 3
 4namespace Anichron.Worker.Crawling;
 5
 6/// <summary>Duplicate content found by one config's crawl.</summary>
 7/// <param name="CopiesWithin">Second copies of stored content at another path in the crawled config.</param>
 8/// <param name="PairsAcross">Pairs of the same content in the crawled config and another of the user's configs.</param>
 9public sealed record DuplicateCounts(int CopiesWithin, int PairsAcross);
 10
 11internal interface ISharedContentReporter
 12{
 13    Task<DuplicateCounts> ReportAsync(
 14        UserStorageConfig crawled, IReadOnlyCollection<UserStorageConfig> usersConfigs, int copiesWithin, CancellationTo
 15}
 16
 1117internal sealed partial class SharedContentReporter(
 1118    IMediaAssetRepository repository,
 1119    ILogger<SharedContentReporter> logger) : ISharedContentReporter
 20{
 21    public async Task<DuplicateCounts> ReportAsync(
 22        UserStorageConfig crawled, IReadOnlyCollection<UserStorageConfig> usersConfigs, int copiesWithin, CancellationTo
 1023    {
 1024        var configIds = usersConfigs.Select(config => config.Id).Union([crawled.Id]).ToList();
 1025        var locations = await repository.FindSharedContentAsync(configIds, ct);
 26
 1027        var pairs = 0;
 4028        foreach (var content in locations.GroupBy(location => location.ContentHash))
 529        {
 530            var places = content.OrderBy(location => location.StorageConfigId).ToList();
 531            var crawledPairs = places
 532                .SelectMany((first, index) => places.Skip(index + 1).Select(second => (first, second)))
 533                .Where(pair => pair.first.StorageConfigId == crawled.Id || pair.second.StorageConfigId == crawled.Id);
 2734            foreach (var (first, second) in crawledPairs)
 635            {
 636                Log.SharedContent(
 637                    logger, first.ContentHash, first.UserId,
 638                    first.FilePath, first.StorageConfigId, second.FilePath, second.StorageConfigId);
 639                pairs++;
 640            }
 541        }
 42
 1043        if (copiesWithin + pairs > 0)
 644            Log.Summary(logger, crawled.Id, crawled.UserId, copiesWithin, pairs);
 1045        return new DuplicateCounts(copiesWithin, pairs);
 1046    }
 47
 48    private static partial class Log
 49    {
 50        [LoggerMessage(
 51            Level = LogLevel.Debug,
 52            Message = "Duplicate content {ContentHash} for user {UserId}: {FilePath} in storage config {StorageConfigId}
 53                + "and {OtherFilePath} in storage config {OtherStorageConfigId}.")]
 54        public static partial void SharedContent(
 55            ILogger logger, string contentHash, Guid userId,
 56            string filePath, Guid storageConfigId, string otherFilePath, Guid otherStorageConfigId);
 57
 58        [LoggerMessage(
 59            Level = LogLevel.Information,
 60            Message = "Duplicate content in storage config {StorageConfigId} of user {UserId}: copies within it: "
 61                + "{WithinConfigCopies}, pairs with the user's other storage configs: {AcrossConfigPairs}.")]
 62        public static partial void Summary(
 63            ILogger logger, Guid storageConfigId, Guid userId, int withinConfigCopies, int acrossConfigPairs);
 64    }
 65}