Skip to content

Commit

Permalink
refactor(ef-core): split the context query and in-memory linq statements
Browse files Browse the repository at this point in the history
  • Loading branch information
harlam357 committed May 22, 2022
1 parent ab21257 commit b1cd7a3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/HFM.Core/Data/ProteinBenchmarkRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ public async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentifi
public async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable<int> projects) =>
await GetBenchmarksAsync(slotIdentifier, projects, null).ConfigureAwait(false);

private async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable<int> projects, int? count) =>
(await QueryWorkUnitsByClientSlot(slotIdentifier, _context)
private async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable<int> projects, int? count)
{
var query = await QueryWorkUnitsByClientSlot(slotIdentifier, _context)
.Include(x => x.Protein)
.Include(x => x.Client)
.Include(x => x.Platform)
Expand All @@ -193,7 +194,9 @@ private async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentif
.OrderByDescending(y => y.FrameID))
.Where(x => projects.Contains(x.Protein.ProjectID) && x.Frames.Any())
.OrderByDescending(x => x.ID)
.ToListAsync().ConfigureAwait(false))
.ToListAsync().ConfigureAwait(false);

return query
.GroupBy(x =>
(SlotIdentifier: new SlotIdentifier(
ClientIdentifier.FromConnectionString(
Expand All @@ -219,6 +222,7 @@ private async Task<ICollection<ProteinBenchmark>> GetBenchmarksAsync(SlotIdentif
})
.TakeWhile((_, i) => !count.HasValue || i < count)
.ToList();
}

private static IQueryable<WorkUnitEntity> QueryWorkUnitsByClientSlot(SlotIdentifier slotIdentifier, WorkUnitContext context)
{
Expand Down

0 comments on commit b1cd7a3

Please sign in to comment.