From 606bab64bc63c89cda076354eaeb30b345f724c1 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Mon, 12 Dec 2022 13:57:19 +0200 Subject: [PATCH] Fix for handleGetTsCmd when fetchLatestPreviousPoint is enabled --- .../DefaultTbEntityDataSubscriptionService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbEntityDataSubscriptionService.java b/application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbEntityDataSubscriptionService.java index 077a9b63b4..796a4bfea1 100644 --- a/application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbEntityDataSubscriptionService.java +++ b/application/src/main/java/org/thingsboard/server/service/subscription/DefaultTbEntityDataSubscriptionService.java @@ -21,6 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ArrayUtils; import org.checkerframework.checker.nullness.qual.Nullable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -563,8 +564,13 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc for (ReadTsKvQueryResult queryResult : queryResults) { String queryKey = queriesKeys.get(queryResult.getQueryId()); if (queryKey != null) { - entityData.getTimeseries().put(queryKey, queryResult.toTsValues()); - lastTsMap.put(queryKey, queryResult.getLastEntryTs()); + TsValue[] tsValues = entityData.getTimeseries().get(queryKey); + if (tsValues == null) { + tsValues = queryResult.toTsValues(); + } else { + tsValues = ArrayUtils.addAll(tsValues, queryResult.toTsValues()); + } + entityData.getTimeseries().put(queryKey, tsValues); } else { log.warn("ReadTsKvQueryResult for {} {} has queryId not matching the initial query", entityData.getEntityId().getEntityType(), entityData.getEntityId());