mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[influxdb] Fix previous item state performance issues (#11993)
Fixes #11878 Signed-off-by: Joan Pujol <joanpujol@gmail.com>
This commit is contained in:
parent
bb2e4c7c65
commit
0df790c687
@ -87,6 +87,18 @@ public class Influx2FilterCriteriaQueryCreatorImpl implements FilterCriteriaQuer
|
|||||||
flux = flux.filter(restrictions);
|
flux = flux.filter(restrictions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flux = applyOrderingAndPageSize(criteria, flux);
|
||||||
|
|
||||||
|
return flux.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Flux applyOrderingAndPageSize(FilterCriteria criteria, Flux flux) {
|
||||||
|
var lastOptimization = criteria.getOrdering() == FilterCriteria.Ordering.DESCENDING
|
||||||
|
&& criteria.getPageSize() == 1;
|
||||||
|
|
||||||
|
if (lastOptimization) {
|
||||||
|
flux = flux.last();
|
||||||
|
} else {
|
||||||
if (criteria.getOrdering() != null) {
|
if (criteria.getOrdering() != null) {
|
||||||
boolean desc = criteria.getOrdering() == FilterCriteria.Ordering.DESCENDING;
|
boolean desc = criteria.getOrdering() == FilterCriteria.Ordering.DESCENDING;
|
||||||
flux = flux.sort().withDesc(desc).withColumns(new String[] { COLUMN_TIME_NAME_V2 });
|
flux = flux.sort().withDesc(desc).withColumns(new String[] { COLUMN_TIME_NAME_V2 });
|
||||||
@ -96,8 +108,8 @@ public class Influx2FilterCriteriaQueryCreatorImpl implements FilterCriteriaQuer
|
|||||||
flux = flux.limit(criteria.getPageSize()).withPropertyValue("offset",
|
flux = flux.limit(criteria.getPageSize()).withPropertyValue("offset",
|
||||||
criteria.getPageNumber() * criteria.getPageSize());
|
criteria.getPageNumber() * criteria.getPageSize());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return flux.toString();
|
return flux;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String calculateMeasurementName(String itemName) {
|
private String calculateMeasurementName(String itemName) {
|
||||||
|
@ -168,6 +168,18 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
|
|||||||
+ "|> sort(desc:false, columns:[\"_time\"])"));
|
+ "|> sort(desc:false, columns:[\"_time\"])"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreviousState() {
|
||||||
|
FilterCriteria criteria = createBaseCriteria();
|
||||||
|
criteria.setOrdering(FilterCriteria.Ordering.DESCENDING);
|
||||||
|
criteria.setPageSize(1);
|
||||||
|
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
|
||||||
|
assertThat(queryV2,
|
||||||
|
equalTo("from(bucket:\"origin\")\n\t" + "|> range(start:-100y)\n\t"
|
||||||
|
+ "|> filter(fn: (r) => r[\"_measurement\"] == \"sampleItem\")\n\t"
|
||||||
|
+ "|> keep(columns:[\"_measurement\", \"_time\", \"_value\"])\n\t" + "|> last()"));
|
||||||
|
}
|
||||||
|
|
||||||
private FilterCriteria createBaseCriteria() {
|
private FilterCriteria createBaseCriteria() {
|
||||||
return createBaseCriteria(ITEM_NAME);
|
return createBaseCriteria(ITEM_NAME);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user