diff options
author | Pierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com> | 2020-12-02 12:25:40 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-02 20:06:58 +0000 |
commit | 5ca7a4f8b7a5aa33a7638573117fa6ce98578b15 (patch) | |
tree | bf0c8764c6414fbd092d090c5071079731bc6eb0 /server/sonar-db-dao | |
parent | f354f42d0d5b53c714c6a51c52e017565db3d37e (diff) | |
download | sonarqube-5ca7a4f8b7a5aa33a7638573117fa6ce98578b15.tar.gz sonarqube-5ca7a4f8b7a5aa33a7638573117fa6ce98578b15.zip |
SONAR-13793 improve ncloc count performance by using projects instead of components
Diffstat (limited to 'server/sonar-db-dao')
5 files changed, 12 insertions, 31 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java index d4abbce6721..e3191e225af 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java @@ -100,7 +100,7 @@ public class LiveMeasureDao implements Dao { */ public long sumNclocOfBiggestBranch(DbSession dbSession, SumNclocDbQuery dbQuery) { Long ncloc = mapper(dbSession).sumNclocOfBiggestBranch( - NCLOC_KEY, BranchType.BRANCH, dbQuery.getOrganizationUuid(), dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude()); + NCLOC_KEY, BranchType.BRANCH, dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude()); return ncloc == null ? 0L : ncloc; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java index 22e5ee92cc1..a06836fa5f1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java @@ -58,7 +58,6 @@ public interface LiveMeasureMapper { Long sumNclocOfBiggestBranch( @Param("ncloc") String nclocKey, @Param("branchType") BranchType branchType, - @Param("organizationUuid") String organizationUuid, @Param("private") Boolean privateProject, @Nullable @Param("projectUuidToExclude") String projectUuidToExclude); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/SumNclocDbQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/SumNclocDbQuery.java index 892b4ebf374..9f5fe625c8c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/SumNclocDbQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/SumNclocDbQuery.java @@ -27,12 +27,10 @@ import static com.google.common.base.Preconditions.checkNotNull; public class SumNclocDbQuery { private final String projectUuidToExclude; - private final String organizationUuid; private final Boolean onlyPrivateProjects; public SumNclocDbQuery(Builder builder) { projectUuidToExclude = builder.projectUuidToExclude; - organizationUuid = builder.organizationUuid; onlyPrivateProjects = builder.onlyPrivateProjects; } @@ -41,10 +39,6 @@ public class SumNclocDbQuery { return projectUuidToExclude; } - public String getOrganizationUuid() { - return organizationUuid; - } - public Boolean getOnlyPrivateProjects() { return onlyPrivateProjects; } @@ -55,7 +49,6 @@ public class SumNclocDbQuery { public static class Builder { private String projectUuidToExclude; - private String organizationUuid; private Boolean onlyPrivateProjects; private Builder() { @@ -67,18 +60,12 @@ public class SumNclocDbQuery { return this; } - public Builder setOrganizationUuid(String organizationUuid) { - this.organizationUuid = organizationUuid; - return this; - } - public Builder setOnlyPrivateProjects(Boolean onlyPrivateProjects) { this.onlyPrivateProjects = onlyPrivateProjects; return this; } public SumNclocDbQuery build() { - checkNotNull(organizationUuid); checkNotNull(onlyPrivateProjects); return new SumNclocDbQuery(this); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml index 499640bead1..6350e358734 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml @@ -16,7 +16,8 @@ <select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto"> select <include refid="columns"/> from live_measures lm where - lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator="," close=")">#{metricUuid, jdbcType=VARCHAR}</foreach> + lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator="," + close=")">#{metricUuid, jdbcType=VARCHAR}</foreach> and lm.component_uuid in <foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")"> #{componentUuid, jdbcType=VARCHAR} @@ -55,19 +56,13 @@ select b.project_uuid as projectUuid, max(lm.value) as maxncloc from live_measures lm inner join metrics m on m.uuid = lm.metric_uuid - inner join components p on p.uuid = lm.component_uuid - inner join project_branches b on b.uuid = p.uuid + inner join project_branches b on b.uuid = lm.component_uuid and b.branch_type = #{branchType, jdbcType=VARCHAR} + inner join projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK' <where> m.name = #{ncloc, jdbcType=VARCHAR} <if test="private"> and p.private=${_true} </if> - and p.enabled = ${_true} - and p.scope = 'PRJ' - and p.qualifier = 'TRK' - and p.copy_component_uuid is null - and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} - and b.branch_type = #{branchType, jdbcType=VARCHAR} <if test="projectUuidToExclude != null"> and b.project_uuid <> #{projectUuidToExclude,jdbcType=VARCHAR} </if> @@ -178,7 +173,7 @@ </sql> <select id="scrollSelectByComponentUuidAndMetricKeys" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" - resultSetType="FORWARD_ONLY"> + resultSetType="FORWARD_ONLY"> select <include refid="columns"/> from live_measures lm inner join metrics m on m.uuid = lm.metric_uuid where @@ -186,7 +181,8 @@ and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR} </select> - <select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> + <select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" + resultSetType="FORWARD_ONLY"> select <include refid="columns"/> from live_measures lm inner join components p on p.uuid = lm.component_uuid <!-- TODO do we really need another join on components ? Using lm.project_uuid should be enough --> @@ -194,7 +190,8 @@ <where> <if test="query.getMetricUuids() != null"> lm.metric_uuid in - <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> + <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," + close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> </if> and p.enabled = ${_true} <if test="query.qualifiers != null"> @@ -219,7 +216,8 @@ <where> <if test="query.getMetricUuids() != null"> lm.metric_uuid in - <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> + <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," + close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> </if> and p.enabled = ${_true} <if test="query.qualifiers != null"> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java index 16cbecdfe0e..004a7fc1f94 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java @@ -321,7 +321,6 @@ public class LiveMeasureDaoTest { SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) - .setOrganizationUuid(organization.getUuid()) .build(); long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); @@ -334,7 +333,6 @@ public class LiveMeasureDaoTest { db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) - .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .build(); long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); @@ -360,7 +358,6 @@ public class LiveMeasureDaoTest { db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d)); SumNclocDbQuery query = SumNclocDbQuery.builder() - .setOrganizationUuid(organization.getUuid()) .setProjectUuidToExclude(projectToExclude.uuid()) .setOnlyPrivateProjects(false) .build(); |