Skip to content

Commit

Permalink
perf(checker): Remove unnecessary loop cycles
Browse files Browse the repository at this point in the history
Relates #428
  • Loading branch information
litleleprikon committed Jun 15, 2020
1 parent 519641d commit 3cb72a4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion checker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,17 @@ func (triggerChecker *TriggerChecker) getMetricStepsStates(metricName string, me

current = make([]moira.MetricState, 0)

// DO NOT CHANGE
// Specific optimization magic
previousState := last
for valueTimestamp := startTime; valueTimestamp < triggerChecker.until+stepTime; valueTimestamp += stepTime {
difference := moira.MaxInt64(checkPoint-startTime, 0)
stepsDifference := difference / stepTime
if (difference % stepTime) > 0 {
stepsDifference++
}
valueTimestamp := startTime + stepTime*stepsDifference
endTimestamp := triggerChecker.until + stepTime
for ; valueTimestamp < endTimestamp; valueTimestamp += stepTime {
metricNewState, err := triggerChecker.getMetricDataState(&metricName, &metrics, &previousState, &valueTimestamp, &checkPoint)
if err != nil {
return last, current, err
Expand Down

0 comments on commit 3cb72a4

Please sign in to comment.