improvements
This commit is contained in:
parent
98c24632e3
commit
2f4ca3b5be
@ -52,7 +52,8 @@ import org.thingsboard.server.dao.timeseries.SimpleListenableFuture;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.Comparator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -129,16 +130,15 @@ public abstract class AbstractSqlTimeseriesDao extends JpaAbstractDaoListeningEx
|
||||
tsLatestQueue = new TbSqlBlockingQueueWrapper<>(tsLatestParams, hashcodeFunction, tsLatestBatchThreads);
|
||||
|
||||
tsLatestQueue.init(logExecutor, v -> {
|
||||
Map<TsKey, List<TsKvLatestEntity>> tsMap =
|
||||
v.stream().collect(Collectors.groupingBy(ts -> new TsKey(ts.getEntityId(), ts.getStrKey())));
|
||||
|
||||
List<TsKvLatestEntity> latestEntities =
|
||||
tsMap.keySet()
|
||||
.stream()
|
||||
.map(tsMap::get)
|
||||
.map(list -> list.stream().max(Comparator.comparing(TsKvLatestEntity::getTs)).get())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<TsKey, TsKvLatestEntity> trueLatest = new HashMap<>();
|
||||
v.forEach(ts -> {
|
||||
TsKey key = new TsKey(ts.getEntityId(), ts.getKey());
|
||||
TsKvLatestEntity old = trueLatest.get(key);
|
||||
if (old == null || old.getTs() < ts.getTs()) {
|
||||
trueLatest.put(key, ts);
|
||||
}
|
||||
});
|
||||
List<TsKvLatestEntity> latestEntities = new ArrayList<>(trueLatest.values());
|
||||
insertLatestTsRepository.saveOrUpdate(latestEntities);
|
||||
});
|
||||
}
|
||||
|
||||
@ -22,5 +22,5 @@ import java.util.UUID;
|
||||
@Data
|
||||
public class TsKey {
|
||||
private final UUID entityId;
|
||||
private final String key;
|
||||
private final int key;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user