From: Jacek Poreda Date: Mon, 20 Feb 2023 11:05:32 +0000 (+0100) Subject: [NO-JIRA] Optimize query for 'ncloc' metric for largest branch per project X-Git-Tag: 10.0.0.68432~217 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0fb39e83de58a422ad4ae6a0fe25b4163344d5a7;p=sonarqube.git [NO-JIRA] Optimize query for 'ncloc' metric for largest branch per project --- 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 17441f11236..9f04ff22b5e 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 @@ -105,8 +105,8 @@ public class LiveMeasureDao implements Dao { return ncloc == null ? 0L : ncloc; } - public List getLargestBranchNclocPerProject(DbSession dbSession) { - return mapper(dbSession).getLargestBranchNclocPerProject(); + public List getLargestBranchNclocPerProject(DbSession dbSession, String nclocMetricUuid) { + return mapper(dbSession).getLargestBranchNclocPerProject(nclocMetricUuid); } public List selectLargestBranchesLocDistribution(DbSession session, String nclocUuid, String nclocDistributionUuid) { 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 5891b136fd7..e93f7742a24 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 @@ -62,7 +62,7 @@ public interface LiveMeasureMapper { @Param("private") Boolean privateProject, @Nullable @Param("projectUuidToExclude") String projectUuidToExclude); - List getLargestBranchNclocPerProject(); + List getLargestBranchNclocPerProject(@Param("nclocUuid") String nclocUuid); List selectLargestBranchesLocDistribution(@Param("nclocUuid") String nclocUuid, @Param("nclocDistributionUuid") String nclocDistributionUuid); 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 23d5ba24e36..c4d49599fc1 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 @@ -82,34 +82,28 @@ 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 13cf0c87aff..89e34ffd984 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 @@ -376,9 +376,10 @@ public class LiveMeasureDaoTest { @Test public void get_branch_with_max_ncloc_per_project() { Map metrics = setupMetrics(); - setupProjectsWithLoc(metrics.get("ncloc"), metrics.get("ncloc_language_distribution"), metrics.get("lines")); + MetricDto ncloc = metrics.get("ncloc"); + setupProjectsWithLoc(ncloc, metrics.get("ncloc_language_distribution"), metrics.get("lines")); - List results = underTest.getLargestBranchNclocPerProject(db.getSession()); + List results = underTest.getLargestBranchNclocPerProject(db.getSession(), ncloc.getUuid()); assertThat(results).hasSize(5); assertLocForProject(results.get(0), "projectWithTieOnBranchSize", DEFAULT_MAIN_BRANCH_NAME, 250);