[TAM-2039] Add affected sensors to table, add cached alert schedule result for bar sensors#1025
[TAM-2039] Add affected sensors to table, add cached alert schedule result for bar sensors#1025GonzoSpire wants to merge 4 commits intomasterfrom
Conversation
Code Review: TAM-2039 — Add affected sensors to table, add cached alert schedule result for bar sensorsBugs / Logic Errors1. Duplicate sensors in The foreach (var policy in sensor.Policies)
{
if (policy.ScheduleId == id)
{
result.Add(sensor);
continue; // ← skips remaining policies but does NOT exit the outer loop
}
}Fix: use if (sensor.Policies.Any(p => p.ScheduleId == id))
result.Add(sensor);2. Missing timezone conversion in The existing single-point overload converts the input UTC time to the schedule's configured timezone via // Single-point version (correct)
public bool IsWorkingTime(DateTime dateTime)
{
var localTime = ConvertUtcToLocalTime(dateTime);
// ... checks against localTime
// Interval version (missing conversion)
public bool IsWorkingTime(DateTime startTime, DateTime endTime)
{
var currentTime = startTime; // ← no ConvertUtcToLocalTime call
...
}3.
Consider either:
Code Quality4. Both throw new ArgumentException("Start time must be less than end time");The conventional overload includes the parameter name for easier debugging: throw new ArgumentException("Start time must be less than end time", nameof(startTime));5. Commented-out code block in A large block of old logic was left commented out rather than removed. Dead code should be deleted — git history preserves the original if it's needed later. //if (jQuery.isEmptyObject(prevState) && prevState !== undefined) {
// let jstreeState = JSON.parse(localStorage.getItem('jstree'));
// ...
//}6. Formatting issues
Minor / Positive Notes
|
Code Review — TAM-2039: Add affected sensors to table, cached alert schedule result for bar sensorsOverall this is a solid feature addition. There are two genuine bugs and a handful of design concerns worth addressing. Bug 1 — Wrong 12-hour format in
|
Code Review: [TAM-2039] Add affected sensors to table, add cached alert schedule result for bar sensorsOverall this PR contains solid improvements: fixes a 12-hour vs 24-hour bug in schedule serialization, adds interval-based schedule evaluation for bar sensors, and shows affected sensors in the UI. A few issues worth addressing below. Bugs / Logic Errors1.
// src/server/HSMServer.Core/AlertSchedule/AlertScheduleProvider.cs
public void Dispose()
{
if (Interlocked.Exchange(ref _disposed, 1) == 0)
{
_cleanupTimer?.Dispose();
GC.SuppressFinalize(this);
}
}
private int _disposed = 0; // int, not bool, for Interlocked2. In 3. In var utc = utcDateTime.Kind == DateTimeKind.Local
? utcDateTime.ToUniversalTime()
: DateTime.SpecifyKind(utcDateTime, DateTimeKind.Utc); // Unspecified → treated as UTCIf 4. CI workflow: # .github/workflows/claude-review.yml
- uses: actions/checkout@v4
with:
fetch-depth: 1 # was 0Changing from full history to shallow depth of 1 means Code Quality / Maintainability5. Commented-out dead code in The old 6. // AlertScheduleProvider.cs
public void CleanupIntervalCache() // only called by the Timer callbackThis method is an internal implementation detail. It should be 7. private readonly TimeSpan CLEANUP_PERIOD = TimeSpan.FromMinutes(5);C# convention for private 8. Indentation regression in The closing brace of the - }
+}
}The class closing brace should remain indented one level inside the namespace. 9. Extra blank lines in Three consecutive blank lines were added (lines 238–240). One is sufficient. Performance10. // TreeValuesCache.cs
foreach (var sensor in _sensorsById.Values) // iterates ALL sensorsThis runs once per schedule when loading the AlertSchedules index page. For deployments with thousands of sensors and many schedules, this is O(sensors × schedules) per page request. Consider maintaining a reverse index ( 11. Each unique Minor / Positive Notes
|
No description provided.