Browse Source
Merge pull request #9924 from ShvaykaD/fix/slow-query-for-rule-node-ids-search
Optimize rule nodes ids search in the upgrade process
pull/9937/head
Andrew Shvayka
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
33 additions and
5 deletions
-
application/src/main/data/upgrade/3.6.2/schema_update.sql
-
application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
-
application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
-
common/dao-api/src/main/java/org/thingsboard/server/dao/rule/RuleChainService.java
-
dao/src/main/java/org/thingsboard/server/dao/service/Validator.java
-
dao/src/main/java/org/thingsboard/server/dao/sql/rule/RuleNodeRepository.java
-
dao/src/main/resources/sql/schema-entities-idx.sql
|
|
@ -0,0 +1,23 @@ |
|
|
|
|
|
-- |
|
|
|
|
|
-- 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; |
|
|
|
|
|
DROP INDEX IF EXISTS idx_rule_node_type_configuration_version; |
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_type_id_configuration_version ON rule_node(type, id, configuration_version); |
|
|
|
|
|
|
|
|
|
|
|
-- RULE NODE INDEXES UPDATE END |
|
|
@ -276,6 +276,9 @@ public class ThingsboardInstallService { |
|
|
} else { |
|
|
} else { |
|
|
log.info("Skipping images migration. Run the upgrade with fromVersion as '3.6.2-images' to migrate"); |
|
|
log.info("Skipping images migration. Run the upgrade with fromVersion as '3.6.2-images' to migrate"); |
|
|
} |
|
|
} |
|
|
|
|
|
case "3.6.2": |
|
|
|
|
|
log.info("Upgrading ThingsBoard from version 3.6.2 to 3.6.3 ..."); |
|
|
|
|
|
databaseEntitiesUpgradeService.upgradeDatabase("3.6.2"); |
|
|
//TODO DON'T FORGET to update switch statement in the CacheCleanupService if you need to clear the cache
|
|
|
//TODO DON'T FORGET to update switch statement in the CacheCleanupService if you need to clear the cache
|
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
|
|
|
@ -772,6 +772,9 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
break; |
|
|
break; |
|
|
|
|
|
case "3.6.2": |
|
|
|
|
|
updateSchema("3.6.2", 3006002, "3.6.3", 3006003, null); |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
|
|
throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); |
|
|
} |
|
|
} |
|
|
|
|
|
@ -100,6 +100,7 @@ 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); |
|
|
|
|
|
|
|
|
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink); |
|
|
PageData<RuleNodeId> findAllRuleNodeIdsByTypeAndVersionLessThan(String type, int version, PageLink pageLink); |
|
|
|
|
|
@ -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 |
|
|
* <code>IncorrectParameterException</code> exception |
|
|
* |
|
|
* |
|
|
* @param val the val |
|
|
* @param val the val |
|
|
|
|
|
@ -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 configuration_version < :version " + |
|
|
" AND r.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, |
|
|
|
|
|
@ -91,9 +91,7 @@ CREATE INDEX IF NOT EXISTS idx_widgets_bundle_external_id ON widgets_bundle(tena |
|
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_external_id ON rule_node(rule_chain_id, external_id); |
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_external_id ON rule_node(rule_chain_id, external_id); |
|
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_type ON rule_node(type); |
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_type_id_configuration_version ON rule_node(type, id, configuration_version); |
|
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_rule_node_type_configuration_version ON rule_node(type, configuration_version); |
|
|
|
|
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_api_usage_state_entity_id ON api_usage_state(entity_id); |
|
|
CREATE INDEX IF NOT EXISTS idx_api_usage_state_entity_id ON api_usage_state(entity_id); |
|
|
|
|
|
|
|
|
|