cleanup after DI graph rewrite

This commit is contained in:
2026-06-03 17:27:58 -05:00
parent b14189c294
commit 2ffd237ddd
19 changed files with 553 additions and 216 deletions
@@ -112,6 +112,8 @@ public sealed class MainWindowViewModel : ViewModelBase, IDisposable
private bool _isStarted;
private bool _isStarting;
private int _rootUpdateQueued;
private int _statusHardwareCount;
private int _statusSensorCount;
private string _statusText = "";
private TemperatureUnit _temperatureUnit;
private int _updateIntervalIndex;
@@ -1041,14 +1043,21 @@ public sealed class MainWindowViewModel : ViewModelBase, IDisposable
MeasureStartup("MainWindowViewModel.ConfigureRoot", () => root.Configure(TemperatureUnit, ShowHiddenSensors, ShowValueColumn, ShowMinColumn, ShowMaxColumn), GetRootDetail);
MeasureStartup("MainWindowViewModel.RootItems.Add", () => RootItems.Add(root), GetRootDetail);
MeasureStartup("MainWindowViewModel.ApplySensorValuesTimeWindow", ApplySensorValuesTimeWindow, GetRootDetail);
RefreshStatusCounts();
}
// Hardware/sensor counts change only when the tree is rebuilt, so cache them here (called from UpdateRoot) instead
// of re-walking the whole tree and re-aggregating Computer.Hardware on every per-tick UpdateStatus().
private void RefreshStatusCounts()
{
_statusHardwareCount = _hardwareMonitor.Computer.Hardware.Count;
_statusSensorCount = RootItems.FirstOrDefault()?.EnumerateSensors().Count() ?? 0;
}
private void UpdateStatus()
{
int hardwareCount = _hardwareMonitor.Computer.Hardware.Count;
int sensorCount = RootItems.FirstOrDefault()?.EnumerateSensors().Count() ?? 0;
string webServerStatus = RunWebServer ? $", web server {WebServerUrl}" : "";
StatusText = $"{hardwareCount} hardware devices, {sensorCount} sensors, update every {FormatInterval(UpdateInterval)}{webServerStatus}";
StatusText = $"{_statusHardwareCount} hardware devices, {_statusSensorCount} sensors, update every {FormatInterval(UpdateInterval)}{webServerStatus}";
}
private void RestartWebServerIfRunning()
@@ -78,17 +78,20 @@ internal sealed class PlotTrackingService
series.Color = sensorItem.PenColor.Value;
}
// The pipeline below sorts and de-duplicates, so there is no need to OrderBy the whole (potentially 24h)
// history every tick; track the latest timestamp in the same pass instead of assuming the list is ordered.
List<PlotPointViewModel> points = [];
foreach (SensorValue sensorValue in sensor.Values.OrderBy(value => value.Time))
DateTime? latestHistoryTimestamp = null;
foreach (SensorValue sensorValue in sensor.Values)
{
double? displayedValue = SensorFormatter.GetPlotValue(sensor, sensorValue.Value, temperatureUnit);
if (displayedValue is not { } pointValue || !double.IsFinite(pointValue))
continue;
points.Add(new PlotPointViewModel(sensorValue.Time, pointValue));
if (!latestHistoryTimestamp.HasValue || sensorValue.Time > latestHistoryTimestamp.Value)
latestHistoryTimestamp = sensorValue.Time;
}
DateTime? latestHistoryTimestamp = points.Count > 0 ? points[^1].Timestamp : null;
foreach (PlotPointViewModel existingPoint in series.Points)
{
if (now - existingPoint.Timestamp > MaximumSyntheticPlotPointRetention)