|
|
|
@ -79,10 +79,14 @@ import java.util.concurrent.ScheduledFuture; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.thingsboard.server.service.cf.ctx.state.BaseCalculatedFieldState.DEFAULT_LAST_UPDATE_TS; |
|
|
|
|
|
|
|
@Data |
|
|
|
@Slf4j |
|
|
|
public class CalculatedFieldCtx implements Closeable { |
|
|
|
|
|
|
|
private static final long SCHEDULED_UPDATE_DISABLED_VALUE = -1L; |
|
|
|
|
|
|
|
private CalculatedField calculatedField; |
|
|
|
|
|
|
|
private CalculatedFieldId cfId; |
|
|
|
@ -197,7 +201,7 @@ public class CalculatedFieldCtx implements Closeable { |
|
|
|
} |
|
|
|
} |
|
|
|
if (calculatedField.getConfiguration() instanceof ScheduledUpdateSupportedCalculatedFieldConfiguration scheduledConfig) { |
|
|
|
this.scheduledUpdateIntervalMillis = scheduledConfig.isScheduledUpdateEnabled() ? TimeUnit.SECONDS.toMillis(scheduledConfig.getScheduledUpdateInterval()) : -1L; |
|
|
|
this.scheduledUpdateIntervalMillis = scheduledConfig.isScheduledUpdateEnabled() ? TimeUnit.SECONDS.toMillis(scheduledConfig.getScheduledUpdateInterval()) : SCHEDULED_UPDATE_DISABLED_VALUE; |
|
|
|
} |
|
|
|
if (calculatedField.getConfiguration() instanceof RelatedEntitiesAggregationCalculatedFieldConfiguration aggConfig) { |
|
|
|
this.useLatestTs = aggConfig.isUseLatestTs(); |
|
|
|
@ -715,8 +719,8 @@ public class CalculatedFieldCtx implements Closeable { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isScheduledUpdateEnabled() { |
|
|
|
return scheduledUpdateIntervalMillis != -1; |
|
|
|
private boolean isScheduledUpdateDisabled() { |
|
|
|
return scheduledUpdateIntervalMillis == SCHEDULED_UPDATE_DISABLED_VALUE; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean shouldFetchRelationQueryDynamicArgumentsFromDb(CalculatedFieldState state) { |
|
|
|
@ -726,11 +730,11 @@ public class CalculatedFieldCtx implements Closeable { |
|
|
|
return switch (cfType) { |
|
|
|
case PROPAGATION -> true; |
|
|
|
case GEOFENCING -> { |
|
|
|
if (!isScheduledUpdateEnabled()) { |
|
|
|
if (isScheduledUpdateDisabled()) { |
|
|
|
yield false; |
|
|
|
} |
|
|
|
var geofencingState = (GeofencingCalculatedFieldState) state; |
|
|
|
if (geofencingState.getLastDynamicArgumentsRefreshTs() == -1L) { |
|
|
|
if (geofencingState.getLastDynamicArgumentsRefreshTs() == DEFAULT_LAST_UPDATE_TS) { |
|
|
|
yield true; |
|
|
|
} |
|
|
|
yield geofencingState.getLastDynamicArgumentsRefreshTs() < |
|
|
|
@ -744,10 +748,10 @@ public class CalculatedFieldCtx implements Closeable { |
|
|
|
if (!(state instanceof RelatedEntitiesAggregationCalculatedFieldState relatedEntitiesAggState)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!isScheduledUpdateEnabled()) { |
|
|
|
if (isScheduledUpdateDisabled()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (relatedEntitiesAggState.getLastRelatedEntitiesRefreshTs() == -1L) { |
|
|
|
if (relatedEntitiesAggState.getLastRelatedEntitiesRefreshTs() == DEFAULT_LAST_UPDATE_TS) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return relatedEntitiesAggState.getLastRelatedEntitiesRefreshTs() < System.currentTimeMillis() - scheduledUpdateIntervalMillis; |
|
|
|
|