From: Eric Hartmann <112486+ehartmann@users.noreply.github.com> Date: Tue, 11 Dec 2018 15:31:27 +0000 (+0100) Subject: SONARCLOUD-278 Reduce SQL requests on RegisterQualityProfiles X-Git-Tag: 7.5~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=410a07681d5cc51dfcfd1afee0c5f06df30a2d12;p=sonarqube.git SONARCLOUD-278 Reduce SQL requests on RegisterQualityProfiles --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index db8095b83cc..00269c40bb2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.utils.System2; @@ -75,7 +76,7 @@ public class QualityProfileDao implements Dao { return mapper(dbSession).selectBuiltInRuleProfiles(); } - public List selectBuiltInRuleProfilesWithActiveRules(DbSession dbSession) { + public List selectBuiltInRuleProfilesWithActiveRules(DbSession dbSession) { return mapper(dbSession).selectBuiltInRuleProfilesWithActiveRules(); } @@ -135,8 +136,8 @@ public class QualityProfileDao implements Dao { return executeLargeInputs(languages, partition -> mapper(dbSession).selectDefaultProfiles(organization.getUuid(), partition)); } - public List selectDefaultBuiltInProfilesWithoutActiveRules(DbSession dbSession) { - return mapper(dbSession).selectDefaultBuiltInProfilesWithoutActiveRules(); + public List selectDefaultBuiltInProfilesWithoutActiveRules(DbSession dbSession, Set languages) { + return executeLargeInputs(languages, partition -> mapper(dbSession).selectDefaultBuiltInProfilesWithoutActiveRules(partition)); } @CheckForNull @@ -180,6 +181,11 @@ public class QualityProfileDao implements Dao { return mapper(dbSession).selectByNameAndLanguage(organization.getUuid(), name, language); } + @CheckForNull + public QProfileDto selectByRuleProfileUuid(DbSession dbSession, String organizationUuid, String ruleProfileKee) { + return mapper(dbSession).selectByRuleProfileUuid(organizationUuid, ruleProfileKee); + } + public List selectByNameAndLanguages(DbSession dbSession, OrganizationDto organization, String name, Collection languages) { return mapper(dbSession).selectByNameAndLanguages(organization.getUuid(), name, languages); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java index dab4546fd2b..d95a2f7ca33 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java @@ -42,7 +42,7 @@ public interface QualityProfileMapper { List selectBuiltInRuleProfiles(); - List selectBuiltInRuleProfilesWithActiveRules(); + List selectBuiltInRuleProfilesWithActiveRules(); @CheckForNull RulesProfileDto selectRuleProfile(@Param("uuid") String ruleProfileUuid); @@ -52,7 +52,7 @@ public interface QualityProfileMapper { @CheckForNull QProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language); - List selectDefaultBuiltInProfilesWithoutActiveRules(); + List selectDefaultBuiltInProfilesWithoutActiveRules(@Param("languages") List languages); List selectDefaultProfiles( @Param("organizationUuid") String organizationUuid, @@ -64,6 +64,11 @@ public interface QualityProfileMapper { @Param("name") String name, @Param("language") String language); + @CheckForNull + QProfileDto selectByRuleProfileUuid( + @Param("organizationUuid") String organizationUuid, + @Param("ruleProfileUuid") String ruleProfileKee); + List selectByNameAndLanguages( @Param("organizationUuid") String organizationUuid, @Param("name") String name, diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index e6ebcaa4e87..3da11e2c1b9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -138,6 +138,22 @@ and oqp.organization_uuid = dp.organization_uuid + + - + select + from rules_profiles rp + where rp.is_built_in = ${_true} AND EXISTS ( SELECT 1 FROM active_rules ar INNER JOIN rules r ON r.id = ar.rule_id AND r.status <> 'REMOVED' @@ -165,21 +178,6 @@ ) - - + +