Fixed: Size on disk calculation including multi-episode files multiple times

Closes #5296
pull/5307/head
Mark McDowall 2 years ago
parent 9a96dee49d
commit be98862ce0

@ -4,6 +4,7 @@ using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Qualities;
@ -180,5 +181,25 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
stats.Should().HaveCount(1);
stats.First().SizeOnDisk.Should().Be(_episodeFile.Size);
}
[Test]
public void should_not_duplicate_size_for_multi_episode_files()
{
GivenEpisodeWithFile();
GivenEpisode();
GivenEpisodeFile();
var episode2 = _episode.JsonClone();
episode2.Id = 0;
episode2.EpisodeNumber += 1;
Db.Insert(episode2);
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().SizeOnDisk.Should().Be(_episodeFile.Size);
}
}
}

@ -55,7 +55,7 @@ namespace NzbDrone.Core.SeriesStats
return new SqlBuilder()
.Select(@"Episodes.SeriesId AS SeriesId,
Episodes.SeasonNumber,
SUM(COALESCE(EpisodeFiles.Size, 0)) AS SizeOnDisk,
SUM(COALESCE(EpisodeFiles.Size, 0)) * COUNT(DISTINCT EpisodeFiles.Id) / COUNT(EpisodeFiles.Id) AS SizeOnDisk,
GROUP_CONCAT(EpisodeFiles.ReleaseGroup, '|') AS ReleaseGroupsString,
COUNT(*) AS TotalEpisodeCount,
SUM(CASE WHEN AirdateUtc <= @currentDate OR EpisodeFileId > 0 THEN 1 ELSE 0 END) AS AvailableEpisodeCount,

Loading…
Cancel
Save