From 7905ff733382405d64a3d08e3c33a24fb5fde94b Mon Sep 17 00:00:00 2001 From: Alain Kermis Date: Fri, 17 Feb 2023 11:44:37 +0100 Subject: [PATCH] SONAR-18472 Resolve telemetry performance issue Co-authored-by: Jacek Poreda --- .../src/main/java/org/sonar/db/MyBatis.java | 4 +- .../org/sonar/db/measure/LiveMeasureDao.java | 4 + .../sonar/db/measure/LiveMeasureMapper.java | 2 + .../java/org/sonar/db/measure/MeasureDao.java | 4 - .../org/sonar/db/measure/MeasureMapper.java | 1 - ...to.java => ProjectLocDistributionDto.java} | 46 +----------- .../sonar/db/measure/LiveMeasureMapper.xml | 18 +++++ .../org/sonar/db/measure/MeasureMapper.xml | 35 --------- .../sonar/db/measure/LiveMeasureDaoTest.java | 74 ++++++++++++++++--- .../org/sonar/db/measure/MeasureDaoTest.java | 2 + .../telemetry/TelemetryDataLoaderImpl.java | 45 ++++++++--- 11 files changed, 128 insertions(+), 107 deletions(-) rename server/sonar-db-dao/src/main/java/org/sonar/db/measure/{ProjectMeasureDto.java => ProjectLocDistributionDto.java} (51%) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 4823fa8cfab..54647f71c9c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -80,7 +80,7 @@ import org.sonar.db.measure.LargestBranchNclocDto; import org.sonar.db.measure.LiveMeasureMapper; import org.sonar.db.measure.MeasureDto; import org.sonar.db.measure.MeasureMapper; -import org.sonar.db.measure.ProjectMeasureDto; +import org.sonar.db.measure.ProjectLocDistributionDto; import org.sonar.db.metric.MetricMapper; import org.sonar.db.newcodeperiod.NewCodePeriodMapper; import org.sonar.db.notification.NotificationQueueDto; @@ -223,7 +223,7 @@ public class MyBatis { confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class); confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrBranchAnalyzedLanguageCountByProjectDto.class); confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class); - confBuilder.loadAlias("ProjectMeasure", ProjectMeasureDto.class); + confBuilder.loadAlias("ProjectLocDistribution", ProjectLocDistributionDto.class); confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class); confBuilder.loadAlias("PushEvent", PushEventDto.class); confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class); 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 7e5547fc292..17441f11236 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 @@ -109,6 +109,10 @@ public class LiveMeasureDao implements Dao { return mapper(dbSession).getLargestBranchNclocPerProject(); } + public List selectLargestBranchesLocDistribution(DbSession session, String nclocUuid, String nclocDistributionUuid) { + return mapper(session).selectLargestBranchesLocDistribution(nclocUuid, nclocDistributionUuid); + } + public long countProjectsHavingMeasure(DbSession dbSession, String metric) { return mapper(dbSession).countProjectsHavingMeasure(metric); } 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 9d2765d89e3..5891b136fd7 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 @@ -64,6 +64,8 @@ public interface LiveMeasureMapper { List getLargestBranchNclocPerProject(); + List selectLargestBranchesLocDistribution(@Param("nclocUuid") String nclocUuid, @Param("nclocDistributionUuid") String nclocDistributionUuid); + Long countProjectsHavingMeasure( @Param("metric") String metric); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java index df552e3aeb6..2c9fb0a195e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -76,8 +76,4 @@ public class MeasureDao implements Dao { return session.getMapper(MeasureMapper.class); } - public List selectLastMeasureForAllProjects(DbSession session, String metricKey) { - return mapper(session).selectLastMeasureForAllProjects(metricKey); - - } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java index fc395469f89..5b11e844677 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java @@ -42,5 +42,4 @@ public interface MeasureMapper { void insert(MeasureDto measureDto); - List selectLastMeasureForAllProjects(@Param("metricKey") String metricKey); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectLocDistributionDto.java similarity index 51% rename from server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java rename to server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectLocDistributionDto.java index 15c320a70f5..bd310099525 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectLocDistributionDto.java @@ -19,47 +19,9 @@ */ package org.sonar.db.measure; -public class ProjectMeasureDto { - - private String projectUuid; - private Long lastAnalysis; - private long loc; - private String textValue; - - public String getProjectUuid() { - return projectUuid; - } - - public ProjectMeasureDto setProjectUuid(String projectUuid) { - this.projectUuid = projectUuid; - return this; - } - - public String getTextValue() { - return textValue; - } - - public ProjectMeasureDto setTextValue(String textValue) { - this.textValue = textValue; - return this; - } - - public long getLoc() { - return loc; - } - - public ProjectMeasureDto setLoc(long loc) { - this.loc = loc; - return this; - } - - public Long getLastAnalysis() { - return lastAnalysis; - } - - public ProjectMeasureDto setLastAnalysis(Long lastAnalysis) { - this.lastAnalysis = lastAnalysis; - return this; - } +/** + * Loc distribution per language for the largest branch in a project. + */ +public record ProjectLocDistributionDto(String projectUuid, String branchUuid, String locDistribution) { } 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 2612e083b46..23d5ba24e36 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 @@ -112,6 +112,24 @@ order by ncloc desc + - - -