From 0a9bb9c7e33b929dea2329ef7f632fce7b82ecf5 Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Tue, 26 Jul 2022 11:54:03 +0200 Subject: [PATCH] SONAR-17093 - Improve pull endpoints performance --- .../java/org/sonar/db/issue/IssueDao.java | 24 +- .../java/org/sonar/db/issue/IssueMapper.java | 12 +- .../org/sonar/db/issue/IssueMapper.xml | 344 +++++++++--------- .../java/org/sonar/db/issue/IssueDaoTest.java | 53 ++- .../sonar/server/issue/ws/BasePullAction.java | 22 +- .../org/sonar/server/issue/ws/PullAction.java | 8 +- .../server/issue/ws/PullTaintAction.java | 9 +- .../ws/pull/PullActionIssuesRetriever.java | 49 +-- .../pull/PullActionIssuesRetrieverTest.java | 41 +-- 9 files changed, 283 insertions(+), 279 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java index c95ee71c47c..00a47fe64ee 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Set; -import javax.annotation.Nullable; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.Pagination; @@ -37,6 +36,7 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class IssueDao implements Dao { public static final int DEFAULT_PAGE_SIZE = 1000; + public static final int BIG_PAGE_SIZE = 1000000; public Optional selectByKey(DbSession session, String key) { return Optional.ofNullable(mapper(session).selectByKey(key)); @@ -61,27 +61,26 @@ public class IssueDao implements Dao { } public Set selectIssueKeysByComponentUuid(DbSession session, String componentUuid) { - return selectIssueKeysByComponentUuid(session, componentUuid, emptyList(), emptyList(), emptyList(), - null, false); + return mapper(session).selectIssueKeysByComponentUuid(componentUuid); } public Set selectIssueKeysByComponentUuid(DbSession session, String componentUuid, List includingRepositories, List excludingRepositories, - List languages, @Nullable Boolean resolvedOnly, boolean openIssuesOnly) { - return mapper(session).selectIssueKeysByComponentUuid(componentUuid, includingRepositories, excludingRepositories, - languages, resolvedOnly, openIssuesOnly); + List languages, int page) { + return mapper(session).selectIssueKeysByComponentUuidWithFilters(componentUuid, includingRepositories, excludingRepositories, + languages, Pagination.forPage(page).andSize(BIG_PAGE_SIZE)); } - public Set selectIssueKeysByComponentUuidAndChangedSinceDate(DbSession session, String componentUuid, long changedSince) { + public Set selectIssueKeysByComponentUuidAndChangedSinceDate(DbSession session, String componentUuid, long changedSince, int page) { return selectIssueKeysByComponentUuidAndChangedSinceDate(session, componentUuid, changedSince, emptyList(), emptyList(), - emptyList(), null); + emptyList(), page); } public Set selectIssueKeysByComponentUuidAndChangedSinceDate(DbSession session, String componentUuid, long changedSince, List includingRepositories, List excludingRepositories, - List languages, @Nullable Boolean resolvedOnly) { + List languages, int page) { return mapper(session).selectIssueKeysByComponentUuidAndChangedSinceDate(componentUuid, changedSince, - includingRepositories, excludingRepositories, languages, resolvedOnly); + includingRepositories, excludingRepositories, languages, Pagination.forPage(page).andSize(BIG_PAGE_SIZE)); } public List selectByComponentUuidPaginated(DbSession session, String componentUuid, int page) { @@ -145,9 +144,8 @@ public class IssueDao implements Dao { return session.getMapper(IssueMapper.class); } - public List selectByBranch(DbSession dbSession, IssueQueryParams issueQueryParams, int page) { - Pagination pagination = Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE); - return mapper(dbSession).selectByBranch(issueQueryParams, pagination); + public List selectByBranch(DbSession dbSession, Set issueKeysSnapshot, IssueQueryParams issueQueryParams) { + return mapper(dbSession).selectByBranch(issueKeysSnapshot, issueQueryParams.getChangedSince()); } public List selectRecentlyClosedIssues(DbSession dbSession, IssueQueryParams issueQueryParams) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java index 3baf1db3549..f040fc89480 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java @@ -38,17 +38,18 @@ public interface IssueMapper { List selectByKeys(List keys); - Set selectIssueKeysByComponentUuid(@Param("componentUuid") String componentUuid, + Set selectIssueKeysByComponentUuid(@Param("componentUuid") String componentUuid); + + Set selectIssueKeysByComponentUuidWithFilters(@Param("componentUuid") String componentUuid, @Param("includingRepositories") List includingRepositories, @Param("excludingRepositories") List excludingRepositories, - @Param("languages") List languages, @Param("resolvedOnly") @Nullable Boolean resolvedOnly, - @Param("openIssuesOnly") boolean openIssuesOnly); + @Param("languages") List languages, @Param("pagination") Pagination pagination); Set selectIssueKeysByComponentUuidAndChangedSinceDate(@Param("componentUuid") String componentUuid, @Param("changedSince") long changedSince, @Param("includingRepositories") List includingRepositories, @Param("excludingRepositories") List excludingRepositories, - @Param("languages") List languages, @Param("resolvedOnly") @Nullable Boolean resolvedOnly); + @Param("languages") List languages, @Param("pagination") Pagination pagination); List selectByComponentUuidPaginated(@Param("componentUuid") String componentUuid, @Param("pagination") Pagination pagination); @@ -79,9 +80,8 @@ public interface IssueMapper { Collection selectIssueGroupsByComponent(@Param("component") ComponentDto component, @Param("leakPeriodBeginningDate") long leakPeriodBeginningDate); + List selectByBranch(@Param("keys") Set keys, @Nullable @Param("changedSince") Long changedSince); - List selectByBranch(@Param("queryParams") IssueQueryParams issueQueryParams, - @Param("pagination") Pagination pagination); List selectRecentlyClosedIssues(@Param("queryParams") IssueQueryParams issueQueryParams); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml index 0e1d3f71dd6..ae2e340fa64 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml @@ -473,74 +473,212 @@ select i.kee from issues i - - inner join rules r on i.rule_uuid = r.uuid - + where + i.project_uuid=#{componentUuid,jdbcType=VARCHAR} + + + + + + + + + + + - - - result.kee as kee, - result.ruleUuid as ruleUuid, - result.createdAt as createdAt, - result.status as status, - result.ruleType as ruleType, - result.ruleRepo as ruleRepo, - result.ruleKey as ruleKey, - result.message as message, - result.severity as severity, - result.manualSeverity as manualSeverity, - result.type as type, - result.locations as locations, - result.component_uuid, - c.path as filePath, - result.assigneeUuid - - - - t.kee as kee, - t.ruleUuid as ruleUuid, - t.createdAt as createdAt, - t.status as status, - t.ruleType as ruleType, - t.ruleRepo as ruleRepo, - t.ruleKey as ruleKey, - t.message as message, - t.severity as severity, - t.manualSeverity as manualSeverity, - t.type as type, - t.locations as locations, - t.component_uuid, - t.assigneeUuid - - i.kee as kee, i.rule_uuid as ruleUuid, @@ -663,115 +765,21 @@ inner join rules r on r.uuid = i.rule_uuid inner join components p on p.uuid=i.component_uuid where - i.project_uuid = #{queryParams.branchUuid} - AND i.status <> 'CLOSED' - AND i.issue_type <> 4 - - AND i.issue_update_date >= #{queryParams.changedSince,jdbcType=BIGINT} + + i.kee IN + + #{key,jdbcType=VARCHAR} + + + + AND i.issue_update_date >= #{changedSince,jdbcType=BIGINT} - - AND i.status = 'RESOLVED' - - - AND r.plugin_name IN - - #{ruleRepository} - - - - AND r.language IN - - #{language} - - - order by i.kee ASC - limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER} - - - - -