Revert "replaced slow query with multi-call of indexed query"
This reverts commit abfcf32c54e2705171d93abbb563fbdec97def5d and 7c42bb72138536c4f78351c1c992ec0d1780d8ea.
This commit is contained in:
parent
7c42bb7213
commit
4a26fad0a5
@ -313,17 +313,9 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<RuleNodeId> getRuleNodesIdsWithTypeAndVersionLessThan(String type, int toVersion) {
|
private List<RuleNodeId> getRuleNodesIdsWithTypeAndVersionLessThan(String type, int toVersion) {
|
||||||
var ruleNodeIds = new ArrayList<RuleNodeId>();
|
|
||||||
for (int v = 0; v < toVersion; v++) {
|
|
||||||
ruleNodeIds.addAll(getRuleNodesIdsWithTypeAndVersion(type, v));
|
|
||||||
}
|
|
||||||
return ruleNodeIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<RuleNodeId> getRuleNodesIdsWithTypeAndVersion(String type, int version) {
|
|
||||||
var ruleNodeIds = new ArrayList<RuleNodeId>();
|
var ruleNodeIds = new ArrayList<RuleNodeId>();
|
||||||
new PageDataIterable<>(pageLink ->
|
new PageDataIterable<>(pageLink ->
|
||||||
ruleChainService.findAllRuleNodeIdsByTypeAndVersion(type, version, pageLink), DEFAULT_PAGE_SIZE
|
ruleChainService.findAllRuleNodeIdsByTypeAndVersionLessThan(type, toVersion, pageLink), DEFAULT_PAGE_SIZE
|
||||||
).forEach(ruleNodeIds::add);
|
).forEach(ruleNodeIds::add);
|
||||||
return ruleNodeIds;
|
return ruleNodeIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,14 +100,10 @@ public interface RuleChainService extends EntityDaoService {
|
|||||||
|
|
||||||
PageData<RuleNode> findAllRuleNodesByType(String type, PageLink pageLink);
|
PageData<RuleNode> findAllRuleNodesByType(String type, PageLink pageLink);
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "3.6.3")
|
|
||||||
PageData<RuleNode> findAllRuleNodesByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
PageData<RuleNode> findAllRuleNodesByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "3.6.3")
|
|
||||||
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
||||||
|
|
||||||
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersion(String type, int version, PageLink pageLink);
|
|
||||||
|
|
||||||
List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds);
|
List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds);
|
||||||
|
|
||||||
RuleNode saveRuleNode(TenantId tenantId, RuleNode ruleNode);
|
RuleNode saveRuleNode(TenantId tenantId, RuleNode ruleNode);
|
||||||
|
|||||||
@ -81,7 +81,6 @@ import static org.thingsboard.server.dao.service.Validator.validateId;
|
|||||||
import static org.thingsboard.server.dao.service.Validator.validateIds;
|
import static org.thingsboard.server.dao.service.Validator.validateIds;
|
||||||
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
|
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
|
||||||
import static org.thingsboard.server.dao.service.Validator.validatePositiveNumber;
|
import static org.thingsboard.server.dao.service.Validator.validatePositiveNumber;
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateNonNegativeNumber;
|
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateString;
|
import static org.thingsboard.server.dao.service.Validator.validateString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -738,15 +737,6 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
|||||||
return ruleNodeDao.findAllRuleNodeIdsByTypeAndVersionLessThan(type, version, pageLink);
|
return ruleNodeDao.findAllRuleNodeIdsByTypeAndVersionLessThan(type, version, pageLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersion(String type, int version, PageLink pageLink) {
|
|
||||||
log.trace("Executing findAllRuleNodeIdsByTypeAndVersion, type {}, pageLink {}, version {}", type, pageLink, version);
|
|
||||||
validateString(type, "Incorrect type of the rule node");
|
|
||||||
validateNonNegativeNumber(version, "Incorrect version. Version should be non-negative!");
|
|
||||||
validatePageLink(pageLink);
|
|
||||||
return ruleNodeDao.findAllRuleNodeIdsByTypeAndVersion(type, version, pageLink);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds) {
|
public List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds) {
|
||||||
log.trace("Executing findAllRuleNodesByIds, ruleNodeIds {}", ruleNodeIds);
|
log.trace("Executing findAllRuleNodesByIds, ruleNodeIds {}", ruleNodeIds);
|
||||||
|
|||||||
@ -38,8 +38,6 @@ public interface RuleNodeDao extends Dao<RuleNode> {
|
|||||||
|
|
||||||
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink);
|
||||||
|
|
||||||
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersion(String type, int version, PageLink pageLink);
|
|
||||||
|
|
||||||
List<RuleNode> findAllRuleNodeByIds(List<RuleNodeId> ruleNodeIds);
|
List<RuleNode> findAllRuleNodeByIds(List<RuleNodeId> ruleNodeIds);
|
||||||
|
|
||||||
List<RuleNode> findByExternalIds(RuleChainId ruleChainId, List<RuleNodeId> externalIds);
|
List<RuleNode> findByExternalIds(RuleChainId ruleChainId, List<RuleNodeId> externalIds);
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class Validator {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method validate <code>long</code> value. If value isn't positive than throw
|
* This method validate <code>long</code> value. If value isn't possitive than throw
|
||||||
* <code>IncorrectParameterException</code> exception
|
* <code>IncorrectParameterException</code> exception
|
||||||
*
|
*
|
||||||
* @param val the val
|
* @param val the val
|
||||||
@ -73,19 +73,6 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method validate <code>long</code> value. If value is negative than throw
|
|
||||||
* <code>IncorrectParameterException</code> exception
|
|
||||||
*
|
|
||||||
* @param val the val
|
|
||||||
* @param errorMessage the error message for exception
|
|
||||||
*/
|
|
||||||
public static void validateNonNegativeNumber(long val, String errorMessage) {
|
|
||||||
if (val < 0) {
|
|
||||||
throw new IncorrectParameterException(errorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method validate <code>UUID</code> id. If id is null than throw
|
* This method validate <code>UUID</code> id. If id is null than throw
|
||||||
* <code>IncorrectParameterException</code> exception
|
* <code>IncorrectParameterException</code> exception
|
||||||
|
|||||||
@ -89,16 +89,6 @@ public class JpaRuleNodeDao extends JpaAbstractDao<RuleNodeEntity, RuleNode> imp
|
|||||||
.mapData(RuleNodeId::new);
|
.mapData(RuleNodeId::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersion(String type, int version, PageLink pageLink) {
|
|
||||||
return DaoUtil.pageToPageData(ruleNodeRepository
|
|
||||||
.findAllRuleNodeIdsByTypeAndVersion(
|
|
||||||
type,
|
|
||||||
version,
|
|
||||||
DaoUtil.toPageable(pageLink)))
|
|
||||||
.mapData(RuleNodeId::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RuleNode> findAllRuleNodeByIds(List<RuleNodeId> ruleNodeIds) {
|
public List<RuleNode> findAllRuleNodeByIds(List<RuleNodeId> ruleNodeIds) {
|
||||||
return DaoUtil.convertDataList(ruleNodeRepository.findAllById(
|
return DaoUtil.convertDataList(ruleNodeRepository.findAllById(
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public interface RuleNodeRepository extends JpaRepository<RuleNodeEntity, UUID>
|
|||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
@Query(nativeQuery = true, value = "SELECT * FROM rule_node r WHERE r.type = :ruleType " +
|
@Query(nativeQuery = true, value = "SELECT * FROM rule_node r WHERE r.type = :ruleType " +
|
||||||
" AND r.configuration_version < :version " +
|
" AND configuration_version < :version " +
|
||||||
" AND (:searchText IS NULL OR r.configuration ILIKE CONCAT('%', :searchText, '%'))")
|
" AND (:searchText IS NULL OR r.configuration ILIKE CONCAT('%', :searchText, '%'))")
|
||||||
Page<RuleNodeEntity> findAllRuleNodesByTypeAndVersionLessThan(@Param("ruleType") String ruleType,
|
Page<RuleNodeEntity> findAllRuleNodesByTypeAndVersionLessThan(@Param("ruleType") String ruleType,
|
||||||
@Param("version") int version,
|
@Param("version") int version,
|
||||||
@ -55,11 +55,6 @@ public interface RuleNodeRepository extends JpaRepository<RuleNodeEntity, UUID>
|
|||||||
@Param("version") int version,
|
@Param("version") int version,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT r.id FROM RuleNodeEntity r WHERE r.type = :ruleType AND r.configurationVersion = :version")
|
|
||||||
Page<UUID> findAllRuleNodeIdsByTypeAndVersion(@Param("ruleType") String ruleType,
|
|
||||||
@Param("version") int version,
|
|
||||||
Pageable pageable);
|
|
||||||
|
|
||||||
List<RuleNodeEntity> findRuleNodesByRuleChainIdAndExternalIdIn(UUID ruleChainId, List<UUID> externalIds);
|
List<RuleNodeEntity> findRuleNodesByRuleChainIdAndExternalIdIn(UUID ruleChainId, List<UUID> externalIds);
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
@ -144,25 +144,6 @@ public class JpaRuleNodeDaoTest extends AbstractJpaDaoTest {
|
|||||||
assertEquals(10, ruleNodeIds.getData().size());
|
assertEquals(10, ruleNodeIds.getData().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFindRuleNodeIdsByTypeAndVersion() {
|
|
||||||
PageData<RuleNodeId> ruleNodeIds = ruleNodeDao.findAllRuleNodeIdsByTypeAndVersion( "A", 0, new PageLink(10, 0, PREFIX_FOR_RULE_NODE_NAME));
|
|
||||||
assertEquals(20, ruleNodeIds.getTotalElements());
|
|
||||||
assertEquals(2, ruleNodeIds.getTotalPages());
|
|
||||||
assertEquals(10, ruleNodeIds.getData().size());
|
|
||||||
|
|
||||||
ruleNodeIds = ruleNodeDao.findAllRuleNodeIdsByTypeAndVersion( "A", 0, new PageLink(10, 0));
|
|
||||||
assertEquals(20, ruleNodeIds.getTotalElements());
|
|
||||||
assertEquals(2, ruleNodeIds.getTotalPages());
|
|
||||||
assertEquals(10, ruleNodeIds.getData().size());
|
|
||||||
|
|
||||||
// test - search text ignored
|
|
||||||
ruleNodeIds = ruleNodeDao.findAllRuleNodeIdsByTypeAndVersion( "A", 0, new PageLink(10, 0, StringUtils.randomAlphabetic(5)));
|
|
||||||
assertEquals(20, ruleNodeIds.getTotalElements());
|
|
||||||
assertEquals(2, ruleNodeIds.getTotalPages());
|
|
||||||
assertEquals(10, ruleNodeIds.getData().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAllRuleNodeByIds() {
|
public void testFindAllRuleNodeByIds() {
|
||||||
var fromUUIDs = ruleNodeIds.stream().map(RuleNodeId::new).collect(Collectors.toList());
|
var fromUUIDs = ruleNodeIds.stream().map(RuleNodeId::new).collect(Collectors.toList());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user