From 430e96cdb220d0186035af2f009415a5f8c48046 Mon Sep 17 00:00:00 2001 From: Andrii Shvaika Date: Mon, 15 Mar 2021 14:50:26 +0200 Subject: [PATCH] Fix Latest TS Dao to save newest record with same timestamp. Enabled updates for old timeseries data. --- .../server/service/subscription/TbEntityDataSubCtx.java | 3 ++- .../thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java b/application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java index 98f5663c1b..fd09536c72 100644 --- a/application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java +++ b/application/src/main/java/org/thingsboard/server/service/subscription/TbEntityDataSubCtx.java @@ -137,7 +137,8 @@ public class TbEntityDataSubCtx extends TbAbstractDataSubCtx { for (TsValue update : new ArrayList<>(updateList)) { if (update.getTs() < v.getTs()) { log.trace("[{}][{}][{}] Removed stale update for key: {} and ts: {}", sessionId, cmdId, subscriptionUpdate.getSubscriptionId(), k, update.getTs()); - updateList.remove(update); + // Looks like this is redundant feature and our UI is ready to merge the updates. + //updateList.remove(update); } else if ((update.getTs() == v.getTs() && update.getValue().equals(v.getValue()))) { log.trace("[{}][{}][{}] Removed duplicate update for key: {} and ts: {}", sessionId, cmdId, subscriptionUpdate.getSubscriptionId(), k, update.getTs()); updateList.remove(update); diff --git a/dao/src/main/java/org/thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.java b/dao/src/main/java/org/thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.java index 43e972339d..3937b7c2c5 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sqlts/SqlTimeseriesLatestDao.java @@ -123,7 +123,7 @@ public class SqlTimeseriesLatestDao extends BaseAbstractSqlTimeseriesDao impleme Map trueLatest = new HashMap<>(); v.forEach(ts -> { TsKey key = new TsKey(ts.getEntityId(), ts.getKey()); - trueLatest.merge(key, ts, (oldTs, newTs) -> oldTs.getTs() < newTs.getTs() ? newTs : oldTs); + trueLatest.merge(key, ts, (oldTs, newTs) -> oldTs.getTs() <= newTs.getTs() ? newTs : oldTs); }); List latestEntities = new ArrayList<>(trueLatest.values()); if (batchSortEnabled) {