Skip to content

Commit de61cad

Browse files
Addresses a performance issue on the dashboard. (#738)
* Addresses a performance issue on the dashboard. Using the MI Date table for this query resulted in a cartesian explosion. The results where correct, but the query plan was awful, it ended up doing multiple scans (18,000+) of the participant table. This tweaked query skips the MI table and just scans the converted date. This is needed to get the full count, but it is better to do it once rather than tens of thousands of times.
1 parent f8bb361 commit de61cad

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

src/Server.UI/Pages/Dashboard/Components/SyncComponent.razor.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ protected override async Task OnInitializedAsync()
1616
{
1717
var uow = GetNewUnitOfWork();
1818

19-
var query = from d in uow.DbContext.DateDimensions
20-
join p in uow.DbContext.Participants
21-
on true equals true// placeholder for where join is done in `where`
22-
where p.LastSyncDate >= d.TheDate &&
23-
p.LastSyncDate < d.TheDate.AddDays(1)
24-
group p by d.TheDate
25-
into g
26-
orderby g.Key
19+
var query = from p in uow.DbContext.Participants
20+
where p.LastSyncDate.HasValue
21+
group p by p.LastSyncDate!.Value.Date into g
22+
orderby g.Key descending
2723
select new SyncRecord(g.Key, g.Count());
2824

29-
30-
var results = await query.ToArrayAsync();
25+
var results = await query.AsNoTracking()
26+
.ToArrayAsync();
27+
3128
if (IsDisposed == false)
3229
{
3330
_records = results;
@@ -40,5 +37,5 @@ orderby g.Key
4037

4138
}
4239

43-
public record SyncRecord(DateTime TheDate, int RecordCount);
40+
private record SyncRecord(DateTime TheDate, int RecordCount);
4441
}

0 commit comments

Comments
 (0)