This commit is contained in:
ngfrolov 2024-02-02 12:14:25 +05:00
parent d7cd45210a
commit b9bbb06584
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -40,20 +40,19 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
if (!idTelemetries.Any())
return;
var statsQuery = await db.Set<DataSaubStat>()
var stats = await db.Set<DataSaubStat>()
.Where(s => idTelemetries.Contains(s.IdTelemetry))
.ToArrayAsync(token);
var stats = statsQuery
.GroupBy(s => s.IdTelemetry)
.ToDictionary(
g => g.Key,
g => g.OrderByDescending(s => s.DateEnd).First()
);
.Select(g => new
{
IdTelemetry = g.Key,
DateEnd = g.Max(s => s.DateEnd),
})
.ToArrayAsync(token);
foreach ( var idTelemetry in idTelemetries)
{
var lastDate = stats.GetValueOrDefault(idTelemetry)?.DateEnd ?? DateTimeOffset.UnixEpoch;
var lastDate = stats.FirstOrDefault(s=>s.IdTelemetry == idTelemetry)?.DateEnd ?? DateTimeOffset.UnixEpoch;
await CreateStatForTelemetryFromDate(db, idTelemetry, lastDate, token);
}
}