Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -109,7 +110,7 @@ public int create(final ScaleRuleDTO scaleRuleDTO) {
final ScaleRuleDO scaleRuleDO = ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO);
int rows = scaleRuleMapper.insertSelective(scaleRuleDO);
if (rows > 0) {
scaleRuleCache.addOrUpdateRuleToCache(ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO));
scaleRuleCache.addOrUpdateRuleToCache(scaleRuleDO);
}
return rows;
}
Expand All @@ -122,9 +123,13 @@ public int create(final ScaleRuleDTO scaleRuleDTO) {
*/
@Override
public int update(final ScaleRuleDTO scaleRuleDTO) {
final ScaleRuleDO before = scaleRuleMapper.selectByPrimaryKey(scaleRuleDTO.getId());
final ScaleRuleDO after = ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO);
int rows = scaleRuleMapper.updateByPrimaryKeySelective(after);
if (rows > 0) {
if (Objects.nonNull(before) && !Objects.equals(before.getMetricName(), after.getMetricName())) {
scaleRuleCache.removeRulesFromCache(List.of(before.getMetricName()));
}
final ScaleRuleDO persisted = scaleRuleMapper.selectByPrimaryKey(scaleRuleDTO.getId());
scaleRuleCache.addOrUpdateRuleToCache(persisted);
}
Expand Down
Loading