perf(applications): scope latest mail to filtered candidates

This commit is contained in:
cesnimda
2026-11-19 20:47:27 +01:00
parent 2a212c78d2
commit 1047dfa267
3 changed files with 44 additions and 12 deletions
@@ -538,7 +538,9 @@ Canonical profile:
{
// Both filters depend on rule evaluation and workflow signals that include normalized
// note content, so evaluate before pagination to keep totals/pages correct.
var latestMessages = await LoadLatestMessagesAsync(_db.Correspondences.AsNoTracking());
var candidateIds = query.Select(j => j.Id);
var latestMessages = await LoadLatestMessagesAsync(_db.Correspondences.AsNoTracking()
.Where(message => candidateIds.Contains(message.JobApplicationId)));
var pre = await query.ToListAsync(cancellationToken);
var filtered = new List<JobApplication>();
foreach (var j in pre)