aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com>2020-12-02 12:25:40 +0100
committersonartech <sonartech@sonarsource.com>2020-12-02 20:06:58 +0000
commit5ca7a4f8b7a5aa33a7638573117fa6ce98578b15 (patch)
treebf0c8764c6414fbd092d090c5071079731bc6eb0 /server
parentf354f42d0d5b53c714c6a51c52e017565db3d37e (diff)
downloadsonarqube-5ca7a4f8b7a5aa33a7638573117fa6ce98578b15.tar.gz
sonarqube-5ca7a4f8b7a5aa33a7638573117fa6ce98578b15.zip
SONAR-13793 improve ncloc count performance by using projects instead of components
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/SumNclocDbQuery.java13
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml24
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java3
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java9
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/MarketplaceAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/MarketplaceActionTest.java2
9 files changed, 19 insertions, 44 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 &lt;&gt; #{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();
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
index 0eda7898f94..202835901f8 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
@@ -58,19 +58,18 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
private final UserIndex userIndex;
private final ProjectMeasuresIndex projectMeasuresIndex;
private final PlatformEditionProvider editionProvider;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
private final InternalProperties internalProperties;
private final DockerSupport dockerSupport;
@CheckForNull
private final LicenseReader licenseReader;
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties, DockerSupport dockerSupport) {
- this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, defaultOrganizationProvider, internalProperties, dockerSupport, null);
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties, DockerSupport dockerSupport) {
+ this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, internalProperties, dockerSupport, null);
}
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties,
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties,
DockerSupport dockerSupport, @Nullable LicenseReader licenseReader) {
this.server = server;
this.dbClient = dbClient;
@@ -78,7 +77,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
this.userIndex = userIndex;
this.projectMeasuresIndex = projectMeasuresIndex;
this.editionProvider = editionProvider;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
this.internalProperties = internalProperties;
this.dockerSupport = dockerSupport;
this.licenseReader = licenseReader;
@@ -115,7 +113,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession));
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.build();
data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query));
long numberOfUnanalyzedCMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_C_KEY);
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
index 5e47becce65..581b78ee09e 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
@@ -81,9 +81,9 @@ public class TelemetryDataLoaderImplTest {
private final LicenseReader licenseReader = mock(LicenseReader.class);
private final TelemetryDataLoader communityUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2),
- new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, null);
+ new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, internalProperties, dockerSupport, null);
private final TelemetryDataLoader commercialUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2),
- new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, licenseReader);
+ new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, internalProperties, dockerSupport, licenseReader);
@Test
public void send_telemetry_data() {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/MarketplaceAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/MarketplaceAction.java
index e6124ef291d..91191e57b8c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/MarketplaceAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/MarketplaceAction.java
@@ -36,13 +36,11 @@ public class MarketplaceAction implements NavigationWsAction {
private final UserSession userSession;
private final Server server;
private final DbClient dbClient;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public MarketplaceAction(UserSession userSession, Server server, DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public MarketplaceAction(UserSession userSession, Server server, DbClient dbClient) {
this.userSession = userSession;
this.server = server;
this.dbClient = dbClient;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
@@ -73,7 +71,6 @@ public class MarketplaceAction implements NavigationWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
SumNclocDbQuery query = SumNclocDbQuery.builder()
.setOnlyPrivateProjects(false)
- .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.build();
return dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/MarketplaceActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/MarketplaceActionTest.java
index 8590131e376..6dca76a8206 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/MarketplaceActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/MarketplaceActionTest.java
@@ -58,7 +58,7 @@ public class MarketplaceActionTest {
private Server server = mock(Server.class);
private DbClient dbClient = db.getDbClient();
- private MarketplaceAction underTest = new MarketplaceAction(userSessionRule, server, dbClient, new DefaultOrganizationProviderImpl(dbClient));
+ private MarketplaceAction underTest = new MarketplaceAction(userSessionRule, server, dbClient);
private WsActionTester ws = new WsActionTester(underTest);