From b1cd7a36abe69ec0ec873c38634be74b891817b9 Mon Sep 17 00:00:00 2001 From: harlam357 Date: Sun, 22 May 2022 18:42:24 -0500 Subject: [PATCH] refactor(ef-core): split the context query and in-memory linq statements --- src/HFM.Core/Data/ProteinBenchmarkRepository.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/HFM.Core/Data/ProteinBenchmarkRepository.cs b/src/HFM.Core/Data/ProteinBenchmarkRepository.cs index e0e4c3df..7d7ca7c1 100644 --- a/src/HFM.Core/Data/ProteinBenchmarkRepository.cs +++ b/src/HFM.Core/Data/ProteinBenchmarkRepository.cs @@ -183,8 +183,9 @@ public async Task> GetBenchmarksAsync(SlotIdentifi public async Task> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable projects) => await GetBenchmarksAsync(slotIdentifier, projects, null).ConfigureAwait(false); - private async Task> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable projects, int? count) => - (await QueryWorkUnitsByClientSlot(slotIdentifier, _context) + private async Task> GetBenchmarksAsync(SlotIdentifier slotIdentifier, IEnumerable projects, int? count) + { + var query = await QueryWorkUnitsByClientSlot(slotIdentifier, _context) .Include(x => x.Protein) .Include(x => x.Client) .Include(x => x.Platform) @@ -193,7 +194,9 @@ private async Task> 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( @@ -219,6 +222,7 @@ private async Task> GetBenchmarksAsync(SlotIdentif }) .TakeWhile((_, i) => !count.HasValue || i < count) .ToList(); + } private static IQueryable QueryWorkUnitsByClientSlot(SlotIdentifier slotIdentifier, WorkUnitContext context) {