From fcab65b3e087ef726b9aaa221f1029d8ca0c818a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Fri, 20 Sep 2024 13:52:33 +0200 Subject: [PATCH] =?UTF-8?q?[rrd4j]=20Avoid=20RrdDb.getRrdDef=20calls=20Sig?= =?UTF-8?q?ned-off-by:=20J=C3=B6rg=20Sautter=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rrd4j/internal/RRD4jPersistenceService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java index 059e8cf6cc4ac..1524b44269f8c 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java @@ -374,8 +374,7 @@ private synchronized void writePointToDatabase(String name, double value, long t // only do it if there is not already a value double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE); if (!Double.isNaN(lastValue) && lastValue != value) { - Sample sample = db.createSample(); - sample.setTime(timestamp - 1); + Sample sample = db.createSample(timestamp - 1); sample.setValue(DATASOURCE_STATE, lastValue); sample.update(); logger.debug("Stored '{}' as value '{}' with timestamp {} in rrd4j database (again)", name, @@ -387,12 +386,11 @@ private synchronized void writePointToDatabase(String name, double value, long t } } try { - Sample sample = db.createSample(); - sample.setTime(timestamp); + Sample sample = db.createSample(timestamp); double storeValue = value; if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) { // counter values must be adjusted by stepsize - storeValue = value * db.getRrdDef().getStep(); + storeValue = value * db.getHeader().getStep(); } sample.setValue(DATASOURCE_STATE, storeValue); sample.update(); @@ -469,7 +467,7 @@ public Iterable query(FilterCriteria filter) { if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1 && filter.getPageNumber() == 0) { if (filterEndDate == null || Duration.between(filterEndDate, ZonedDateTime.now()).getSeconds() < db - .getRrdDef().getStep()) { + .getHeader().getStep()) { // we are asked only for the most recent value! double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE); if (!Double.isNaN(lastValue)) { @@ -628,7 +626,7 @@ public Set getItemInfo() { public ConsolFun getConsolidationFunction(RrdDb db) { try { - return db.getRrdDef().getArcDefs()[0].getConsolFun(); + return db.getArchive(0).getConsolFun(); } catch (IOException e) { return ConsolFun.MAX; }