Skip to content

Commit

Permalink
[rrd4j] Reuse the state for identical values (#16379)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
  • Loading branch information
joerg1985 committed Feb 8, 2024
1 parent 8b2148e commit eff4496
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,21 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
long ts = result.getFirstTimestamp();
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(ts), ZoneId.systemDefault());
long step = result.getRowCount() > 1 ? result.getStep() : 0;

double prevValue = Double.NaN;
State prevState = null;
for (double value : result.getValues(DATASOURCE_STATE)) {
if (!Double.isNaN(value) && (((ts >= start) && (ts <= end)) || (start == end))) {
RRD4jItem rrd4jItem = new RRD4jItem(itemName, toState.apply(value), zdt);
State state;

if (prevValue == value) {
state = prevState;
} else {
prevState = state = toState.apply(value);
prevValue = value;
}

RRD4jItem rrd4jItem = new RRD4jItem(itemName, state, zdt);
items.add(rrd4jItem);
}
zdt = zdt.plusSeconds(step);
Expand Down

0 comments on commit eff4496

Please sign in to comment.