Skip to content

Commit

Permalink
CDMS-179 optimises Movements ByItemCount analytics for bigger datasets (
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds authored Dec 10, 2024
1 parent 07cd1ae commit 70ab5ac
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Btms.Analytics/MovementsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using MongoDB.Driver;

using Btms.Analytics.Extensions;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;

namespace Btms.Analytics;

Expand Down Expand Up @@ -58,17 +59,11 @@ public Task<MultiSeriesDataset[]> ByItemCount(DateTime from, DateTime to)
var mongoQuery = context
.Movements
.Where(n => n.CreatedSource >= from && n.CreatedSource < to)
.GroupBy(m => new { Linked = m.Relationships.Notifications.Data.Count > 0, Items = m.Items.Count })
.GroupBy(g => g.Key.Linked);

.GroupBy(m => new { Linked = m.Relationships.Notifications.Data.Count > 0, ItemCount = m.Items.Count })
.Select(g => new { g.Key.Linked, g.Key.ItemCount, Count = g.Count() });
var mongoResult = mongoQuery
.Execute(logger)
.SelectMany(g => g.Select(l => new
{
Linked = g.Key,
ItemCount = l.Key.Items,
Count = l.Count()
}))
.ToList();

var dictionary = mongoResult
Expand Down

0 comments on commit 70ab5ac

Please sign in to comment.