diff --git a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeCacheKey.java b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeCacheKey.java index 05a7c55898..10771656e9 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeCacheKey.java +++ b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeCacheKey.java @@ -20,10 +20,14 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import org.thingsboard.server.common.data.id.EntityId; +import java.io.Serializable; + @EqualsAndHashCode @Getter @AllArgsConstructor -public class AttributeCacheKey { +public class AttributeCacheKey implements Serializable { + private static final long serialVersionUID = 2013369077925351881L; + private final String scope; private final EntityId entityId; private final String key; diff --git a/dao/src/main/java/org/thingsboard/server/dao/attributes/CachedAttributesService.java b/dao/src/main/java/org/thingsboard/server/dao/attributes/CachedAttributesService.java index 22e9a95bd6..6ebebdbcaa 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/attributes/CachedAttributesService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/attributes/CachedAttributesService.java @@ -37,10 +37,12 @@ import org.thingsboard.server.dao.service.Validator; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import static org.thingsboard.server.common.data.CacheConstants.ATTRIBUTES_CACHE; @@ -106,13 +108,11 @@ public class CachedAttributesService implements AttributesService { return Futures.immediateFuture(cachedAttributes); } - ArrayList notFoundAttributeKeys = new ArrayList<>(attributeKeys); + Set notFoundAttributeKeys = new HashSet<>(attributeKeys); notFoundAttributeKeys.removeAll(wrappedCachedAttributes.keySet()); ListenableFuture> result = attributesDao.find(tenantId, entityId, scope, notFoundAttributeKeys); - return Futures.transform(result, foundInDbAttributes -> { - return mergeDbAndCacheAttributes(entityId, scope, cachedAttributes, notFoundAttributeKeys, foundInDbAttributes); - }, MoreExecutors.directExecutor()); + return Futures.transform(result, foundInDbAttributes -> mergeDbAndCacheAttributes(entityId, scope, cachedAttributes, notFoundAttributeKeys, foundInDbAttributes), MoreExecutors.directExecutor()); } @@ -130,7 +130,7 @@ public class CachedAttributesService implements AttributesService { return cachedAttributes; } - private List mergeDbAndCacheAttributes(EntityId entityId, String scope, List cachedAttributes, ArrayList notFoundAttributeKeys, List foundInDbAttributes) { + private List mergeDbAndCacheAttributes(EntityId entityId, String scope, List cachedAttributes, Set notFoundAttributeKeys, List foundInDbAttributes) { for (AttributeKvEntry foundInDbAttribute : foundInDbAttributes) { AttributeCacheKey attributeCacheKey = new AttributeCacheKey(scope, entityId, foundInDbAttribute.getKey()); attributesCache.put(attributeCacheKey, foundInDbAttribute);