forked from ddrilling/AsbCloudServer
draft 3
This commit is contained in:
parent
d7cd45210a
commit
b9bbb06584
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user