From bc4d1696a5998adcadb03c64e21aff4a467a1ab1 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 27 Jul 2021 16:10:33 -0500 Subject: [PATCH] SONAR-15237 Improve startup performance of the web process --- .../main/java/org/sonar/db/rule/RuleDao.java | 4 + .../java/org/sonar/db/rule/RuleMapper.java | 2 + .../db/qualityprofile/ActiveRuleMapper.xml | 4 +- .../org/sonar/db/rule/RuleMapper.xml | 21 +- .../sonar/server/rule/DefaultRuleFinder.java | 30 ++- .../sonar/server/rule/ServerRuleFinder.java | 6 + .../server/rule/DefaultRuleFinderTest.java | 29 ++- .../server/plugins/DetectPluginChange.java | 108 +++++++++++ .../sonar/server/rule/CachingRuleFinder.java | 41 ++-- .../server/rule/WebServerRuleFinder.java | 0 .../server/rule/WebServerRuleFinderImpl.java | 11 ++ .../plugins/DetectPluginChangeTest.java | 116 +++++++++++ .../DefaultAdminCredentialsVerifierImpl.java | 11 +- .../BuiltInQProfileInsertImpl.java | 71 ++++--- .../BuiltInQProfileRepositoryImpl.java | 11 +- ...faultAdminCredentialsVerifierImplTest.java | 15 +- .../BuiltInQProfileInsertImplTest.java | 77 ++++++-- .../BuiltInQProfileRepositoryImplTest.java | 54 +++--- .../org/sonar/server/rule/RegisterRules.java | 180 ++++++++++-------- .../sonar/server/startup/RegisterMetrics.java | 8 +- .../server/rule/CachingRuleFinderTest.java | 3 +- .../sonar/server/rule/RegisterRulesTest.java | 16 +- .../server/startup/RegisterMetricsTest.java | 10 +- .../qualitygate/RegisterQualityGates.java | 7 +- ...gisterQualityProfilesNotificationTest.java | 9 +- .../platform/platformlevel/PlatformLevel.java | 6 +- .../platformlevel/PlatformLevel3.java | 5 +- .../platformlevel/PlatformLevelStartup.java | 51 ++++- 28 files changed, 646 insertions(+), 260 deletions(-) create mode 100644 server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java rename server/{sonar-webserver-core => sonar-webserver-api}/src/main/java/org/sonar/server/rule/CachingRuleFinder.java (86%) rename server/{sonar-webserver-core => sonar-webserver-api}/src/main/java/org/sonar/server/rule/WebServerRuleFinder.java (100%) rename server/{sonar-webserver-core => sonar-webserver-api}/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java (91%) create mode 100644 server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index 59fab5899b4..8507c5885b9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -203,6 +203,10 @@ public class RuleDao implements Dao { return executeLargeInputs(ruleKeys, mapper(session)::selectParamsByRuleKeys); } + public List selectAllRuleParams(DbSession session) { + return mapper(session).selectAllRuleParams(); + } + public List selectRuleParamsByRuleUuids(DbSession dbSession, Collection ruleUuids) { return executeLargeInputs(ruleUuids, mapper(dbSession)::selectParamsByRuleUuids); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java index a49cf2e22a5..b4b815ec7a7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java @@ -81,6 +81,8 @@ public interface RuleMapper { List selectParamsByRuleKeys(@Param("ruleKeys") List ruleKeys); + List selectAllRuleParams(); + void insertParameter(RuleParamDto param); void updateParameter(RuleParamDto param); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml index 8872334858d..8d05ec5155b 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml @@ -36,7 +36,7 @@ inner join rules r on r.uuid = a.rule_uuid - + insert into active_rules ( uuid, profile_uuid, @@ -56,7 +56,7 @@ ) - + update active_rules set failure_level = #{severity, jdbcType=INTEGER}, diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml index ca8ee02db2e..06b8316d728 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -148,7 +148,7 @@ - order by r.created_at asc @@ -324,8 +325,10 @@ where r.status != 'REMOVED' and r.is_external=${_false} and r.is_template=${_false} - and r.rule_type in #{type, jdbcType=INTEGER} - and r.language in #{language, jdbcType=VARCHAR} + and r.rule_type in + #{type, jdbcType=INTEGER} + and r.language in + #{language, jdbcType=VARCHAR} @@ -506,6 +509,13 @@ + +