Skip to content

Commit

Permalink
Use query for list instead of callback in PointValueCache.refreshCache
Browse files Browse the repository at this point in the history
  • Loading branch information
terrypacker committed May 17, 2019
1 parent 4994bb3 commit 334e42e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Core/src/com/serotonin/m2m2/rt/dataImage/PointValueCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,14 @@ private void refreshCache(int size) {
List<PointValueTime> cc = new ArrayList<>(cache.size());
cc.addAll(cache);
nc = new ArrayList<PointValueTime>(size);
dao.getLatestPointValues(dataPointId, timer.currentTimeMillis() + 1, size, (value, index) -> {
//Reset our latest time,
if(index == 0)
latestSavedValueTime.accumulateAndGet(value.getTime(), (updated, current) ->{
return updated > current ? updated : current;
});
List<PointValueTime> latest = dao.getLatestPointValues(dataPointId, size, timer.currentTimeMillis() + 1);
//Reset our latest time,
if(latest.size() > 0)
latestSavedValueTime.accumulateAndGet(latest.get(0).getTime(), (updated, current) ->{
return updated > current ? updated : current;
});

for(PointValueTime value : latest) {
//Cache is in same order as rows
if(nc.size() < size && cc.size() > 0 && cc.get(0).getTime() >= value.getTime()) {
//The cached value is newer or unsaved retain it
Expand All @@ -235,7 +237,7 @@ private void refreshCache(int size) {
if(nc.size() < size)
nc.add(value);
}
});
}
//No values in database, make sure we keep the unsaved values
if(nc.size() == 0) {
while((nc.size() < size && cc.size() > 0) || (cc.size() > 0 && cc.get(0).getTime() > latestSavedValueTime.get()))
Expand Down

0 comments on commit 334e42e

Please sign in to comment.