fix: exclude live tracks under soft-deleted releases from home stats cut/mix figures
This commit is contained in:
@@ -159,16 +159,17 @@ public class TrackRepository : Repository<DeepDrftContext, TrackEntity>
|
||||
.ToDictionaryAsync(x => x.ReleaseId, x => x.Count, ct);
|
||||
|
||||
// Aggregate figures for the public home hero stat row, assembled in as few round-trips as is clean.
|
||||
// All counts go through Query / the release set's !IsDeleted filter so soft-deleted rows never count.
|
||||
// Mix runtime sums DurationSeconds with a null-coalesce to 0 so not-yet-backfilled rows contribute
|
||||
// zero rather than throwing or skewing the total. The cut release-type breakdown is grouped here so
|
||||
// a zero-count type is simply absent from the result (no present-with-zero row).
|
||||
// All counts go through Query (!t.IsDeleted) plus an explicit !t.Release.IsDeleted guard so tracks
|
||||
// under a directly-deleted release are also excluded. Mix runtime sums DurationSeconds with a
|
||||
// null-coalesce to 0 so not-yet-backfilled rows contribute zero rather than throwing or skewing the
|
||||
// total. The cut release-type breakdown is grouped here so a zero-count type is simply absent from
|
||||
// the result (no present-with-zero row).
|
||||
public async Task<HomeStatsDto> GetHomeStatsAsync(CancellationToken ct = default)
|
||||
{
|
||||
var releases = _context.Set<ReleaseEntity>().Where(r => !r.IsDeleted);
|
||||
|
||||
var cutTrackCount = await Query
|
||||
.CountAsync(t => t.Release != null && t.Release.Medium == ReleaseMedium.Cut, ct);
|
||||
.CountAsync(t => t.Release != null && !t.Release.IsDeleted && t.Release.Medium == ReleaseMedium.Cut, ct);
|
||||
|
||||
var cutReleaseTypeCounts = await releases
|
||||
.Where(r => r.Medium == ReleaseMedium.Cut)
|
||||
@@ -180,7 +181,7 @@ public class TrackRepository : Repository<DeepDrftContext, TrackEntity>
|
||||
.CountAsync(r => r.Medium == ReleaseMedium.Mix, ct);
|
||||
|
||||
var mixRuntimeSeconds = await Query
|
||||
.Where(t => t.Release != null && t.Release.Medium == ReleaseMedium.Mix)
|
||||
.Where(t => t.Release != null && !t.Release.IsDeleted && t.Release.Medium == ReleaseMedium.Mix)
|
||||
.SumAsync(t => t.DurationSeconds ?? 0d, ct);
|
||||
|
||||
return new HomeStatsDto
|
||||
|
||||
Reference in New Issue
Block a user