Revert "replaced slow query with multi-call of indexed query"

This reverts commit abfcf32c54e2705171d93abbb563fbdec97def5d and 7c42bb72138536c4f78351c1c992ec0d1780d8ea.
This commit is contained in:
ShvaykaD 2024-01-02 15:31:30 +02:00
parent 7c42bb7213
commit 4a26fad0a5
8 changed files with 3 additions and 74 deletions

View File

@ -313,17 +313,9 @@ public class DefaultDataUpdateService implements DataUpdateService {
}
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>();
new PageDataIterable<>(pageLink ->
ruleChainService.findAllRuleNodeIdsByTypeAndVersion(type, version, pageLink), DEFAULT_PAGE_SIZE
ruleChainService.findAllRuleNodeIdsByTypeAndVersionLessThan(type, toVersion, pageLink), DEFAULT_PAGE_SIZE
).forEach(ruleNodeIds::add);
return ruleNodeIds;
}

View File

@ -100,14 +100,10 @@ public interface RuleChainService extends EntityDaoService {
PageData<RuleNode> findAllRuleNodesByType(String type, PageLink pageLink);
@Deprecated(forRemoval = true, since = "3.6.3")
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> findAllRuleNodeIdsByTypeAndVersion(String type, int version, PageLink pageLink);
List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds);
RuleNode saveRuleNode(TenantId tenantId, RuleNode ruleNode);

View File

@ -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.validatePageLink;
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;
/**
@ -738,15 +737,6 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
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
public List<RuleNode> findAllRuleNodesByIds(List<RuleNodeId> ruleNodeIds) {
log.trace("Executing findAllRuleNodesByIds, ruleNodeIds {}", ruleNodeIds);

View File

@ -38,8 +38,6 @@ public interface RuleNodeDao extends Dao<RuleNode> {
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> findByExternalIds(RuleChainId ruleChainId, List<RuleNodeId> externalIds);

View File

@ -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
*
* @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
* <code>IncorrectParameterException</code> exception

View File

@ -89,16 +89,6 @@ public class JpaRuleNodeDao extends JpaAbstractDao<RuleNodeEntity, RuleNode> imp
.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
public List<RuleNode> findAllRuleNodeByIds(List<RuleNodeId> ruleNodeIds) {
return DaoUtil.convertDataList(ruleNodeRepository.findAllById(

View File

@ -43,7 +43,7 @@ public interface RuleNodeRepository extends JpaRepository<RuleNodeEntity, UUID>
Pageable pageable);
@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, '%'))")
Page<RuleNodeEntity> findAllRuleNodesByTypeAndVersionLessThan(@Param("ruleType") String ruleType,
@Param("version") int version,
@ -55,11 +55,6 @@ public interface RuleNodeRepository extends JpaRepository<RuleNodeEntity, UUID>
@Param("version") int version,
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);
@Transactional

View File

@ -144,25 +144,6 @@ public class JpaRuleNodeDaoTest extends AbstractJpaDaoTest {
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
public void testFindAllRuleNodeByIds() {
var fromUUIDs = ruleNodeIds.stream().map(RuleNodeId::new).collect(Collectors.toList());