Browse Source

added new index for rule nodes ids search query and removed old one

pull/9924/head
ShvaykaD 3 years ago
parent
commit
360e32684e
  1. 22
      application/src/main/data/upgrade/3.6.2/schema_update.sql
  2. 3
      application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
  3. 1
      common/dao-api/src/main/java/org/thingsboard/server/dao/rule/RuleChainService.java
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/service/Validator.java
  5. 2
      dao/src/main/java/org/thingsboard/server/dao/sql/rule/RuleNodeRepository.java
  6. 2
      dao/src/main/resources/sql/schema-entities-idx.sql

22
application/src/main/data/upgrade/3.6.2/schema_update.sql

@ -0,0 +1,22 @@
--
-- Copyright © 2016-2023 The Thingsboard Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- RULE NODE INDEXES UPDATE START
DROP INDEX IF EXISTS idx_rule_node_type_configuration_version;
CREATE INDEX IF NOT EXISTS idx_rule_node_id_type_configuration_version ON rule_node(id, type, configuration_version);
-- RULE NODE INDEXES UPDATE END

3
application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java

@ -772,6 +772,9 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
}
});
break;
case "3.6.2":
updateSchema("3.6.2", 3006002, "3.6.3", 3006003, null);
break;
default:
throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion);
}

1
common/dao-api/src/main/java/org/thingsboard/server/dao/rule/RuleChainService.java

@ -100,6 +100,7 @@ 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);
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink);

2
dao/src/main/java/org/thingsboard/server/dao/service/Validator.java

@ -61,7 +61,7 @@ public class Validator {
/**
* This method validate <code>long</code> value. If value isn't possitive than throw
* This method validate <code>long</code> value. If value isn't positive than throw
* <code>IncorrectParameterException</code> exception
*
* @param val the val

2
dao/src/main/java/org/thingsboard/server/dao/sql/rule/RuleNodeRepository.java

@ -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 configuration_version < :version " +
" AND r.configuration_version < :version " +
" AND (:searchText IS NULL OR r.configuration ILIKE CONCAT('%', :searchText, '%'))")
Page<RuleNodeEntity> findAllRuleNodesByTypeAndVersionLessThan(@Param("ruleType") String ruleType,
@Param("version") int version,

2
dao/src/main/resources/sql/schema-entities-idx.sql

@ -93,7 +93,7 @@ CREATE INDEX IF NOT EXISTS idx_rule_node_external_id ON rule_node(rule_chain_id,
CREATE INDEX IF NOT EXISTS idx_rule_node_type ON rule_node(type);
CREATE INDEX IF NOT EXISTS idx_rule_node_type_configuration_version ON rule_node(type, configuration_version);
CREATE INDEX IF NOT EXISTS idx_rule_node_id_type_configuration_version ON rule_node(id, type, configuration_version);
CREATE INDEX IF NOT EXISTS idx_api_usage_state_entity_id ON api_usage_state(entity_id);

Loading…
Cancel
Save