fix(identity): plan-statistics LINQ translation (aggregate in memory)
Build backend images / build content-svc (push) Failing after 57s
Build backend images / build file-svc (push) Failing after 58s
Build backend images / build gateway (push) Failing after 4m40s
Build backend images / build identity-svc (push) Failing after 56s
Build backend images / build notification-svc (push) Failing after 10s
Build backend images / build render-svc (push) Failing after 4m3s
Build backend images / build studio-svc (push) Failing after 2m24s

EF Core can't translate a conditional Count(predicate) inside a grouped Select;
fetch flat rows then group/aggregate in memory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-02 23:04:53 +03:30
parent 151970accd
commit 24aa4c51a4
@@ -62,16 +62,20 @@ public class AdminService(IdentityDbContext db)
public async Task<List<PlanStatRow>> GetPlanStatisticsAsync(Guid tenantId) public async Task<List<PlanStatRow>> GetPlanStatisticsAsync(Guid tenantId)
{ {
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
return await db.UserPlans // Pull flat rows then aggregate in memory — EF can't translate a conditional
// Count(predicate) inside a grouped Select.
var rows = await db.UserPlans
.Where(p => p.TenantId == tenantId) .Where(p => p.TenantId == tenantId)
.GroupBy(p => p.PlanName) .Select(p => new { p.PlanName, p.ExpiresAt, p.CancelledAt, p.PriceMinorPaid })
.ToListAsync();
return rows.GroupBy(r => r.PlanName)
.Select(g => new PlanStatRow( .Select(g => new PlanStatRow(
g.Key, g.Key,
g.Count(), g.Count(),
g.Count(x => x.ExpiresAt > now && x.CancelledAt == null), g.Count(x => x.ExpiresAt > now && x.CancelledAt == null),
g.Sum(x => x.PriceMinorPaid))) g.Sum(x => x.PriceMinorPaid)))
.OrderByDescending(r => r.RevenueMinor) .OrderByDescending(r => r.RevenueMinor)
.ToListAsync(); .ToList();
} }
// ── CRM notes / tags ──────────────────────────────────────────────────── // ── CRM notes / tags ────────────────────────────────────────────────────