Browse Source

passed tenant profile id to filter unnecessary cfs to update

pull/14253/head
IrynaMatveieva 7 months ago
parent
commit
c0f4bba52c
  1. 3
      application/src/main/java/org/thingsboard/server/service/cf/CalculatedFieldCache.java
  2. 13
      application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldCache.java
  3. 2
      application/src/main/java/org/thingsboard/server/service/queue/processing/AbstractConsumerService.java

3
application/src/main/java/org/thingsboard/server/service/cf/CalculatedFieldCache.java

@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.cf.CalculatedFieldType;
import org.thingsboard.server.common.data.id.CalculatedFieldId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.TenantProfileId;
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldCtx;
import java.util.List;
@ -50,7 +51,7 @@ public interface CalculatedFieldCache {
void evict(CalculatedFieldId calculatedFieldId);
void handleTenantProfileUpdate();
void handleTenantProfileUpdate(TenantProfileId tenantProfileId);
EntityId getProfileId(TenantId tenantId, EntityId entityId);

13
application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldCache.java

@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.thingsboard.server.actors.ActorSystemContext;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.cf.CalculatedField;
import org.thingsboard.server.common.data.cf.CalculatedFieldLink;
import org.thingsboard.server.common.data.cf.CalculatedFieldType;
@ -33,8 +34,10 @@ import org.thingsboard.server.common.data.id.CalculatedFieldId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.TenantProfileId;
import org.thingsboard.server.common.data.page.PageDataIterable;
import org.thingsboard.server.dao.cf.CalculatedFieldService;
import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
import org.thingsboard.server.queue.util.AfterStartUp;
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldCtx;
import org.thingsboard.server.service.profile.TbAssetProfileCache;
@ -61,6 +64,7 @@ public class DefaultCalculatedFieldCache implements CalculatedFieldCache {
private final CalculatedFieldService calculatedFieldService;
private final TbAssetProfileCache assetProfileCache;
private final TbDeviceProfileCache deviceProfileCache;
private final TbTenantProfileCache tenantProfileCache;
@Lazy
private final ActorSystemContext systemContext;
private final OwnerService ownerService;
@ -228,8 +232,13 @@ public class DefaultCalculatedFieldCache implements CalculatedFieldCache {
}
@Override
public void handleTenantProfileUpdate() {
calculatedFieldsCtx.values().forEach(CalculatedFieldCtx::updateTenantProfileProperties);
public void handleTenantProfileUpdate(TenantProfileId tenantProfileId) {
calculatedFieldsCtx.values().stream()
.filter(ctx -> {
TenantProfile tenantProfile = tenantProfileCache.get(ctx.getTenantId());
return tenantProfile != null && tenantProfileId.equals(tenantProfile.getId());
})
.forEach(CalculatedFieldCtx::updateTenantProfileProperties);
}
@Override

2
application/src/main/java/org/thingsboard/server/service/queue/processing/AbstractConsumerService.java

@ -166,7 +166,7 @@ public abstract class AbstractConsumerService<N extends com.google.protobuf.Gene
tenantProfileCache.evict(tenantProfileId);
if (componentLifecycleMsg.getEvent().equals(ComponentLifecycleEvent.UPDATED)) {
apiUsageStateService.onTenantProfileUpdate(tenantProfileId);
calculatedFieldCache.handleTenantProfileUpdate();
calculatedFieldCache.handleTenantProfileUpdate(tenantProfileId);
}
} else if (EntityType.TENANT.equals(componentLifecycleMsg.getEntityId().getEntityType())) {
if (TenantId.SYS_TENANT_ID.equals(tenantId)) {

Loading…
Cancel
Save