aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-05 17:16:43 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-09 10:09:44 +0200
commite7b6e8ea0815497970d57cef27cdf98788535ab0 (patch)
tree90aac34fd5c8caec16fc98f8066f2126541740fb /server/sonar-server
parentf3aae4bbd59805922341a763aada92904a908046 (diff)
downloadsonarqube-e7b6e8ea0815497970d57cef27cdf98788535ab0.tar.gz
sonarqube-e7b6e8ea0815497970d57cef27cdf98788535ab0.zip
SONAR-8061 speed up issue transition removing duplicate SQL
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java19
2 files changed, 24 insertions, 5 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
index f7021444718..acdb637bfeb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
@@ -89,16 +89,18 @@ public class DoTransitionAction implements IssuesWsAction {
String issue = request.mandatoryParam(PARAM_ISSUE);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto issueDto = issueFinder.getByKey(dbSession, issue);
- doTransition(dbSession, issueDto.toDefaultIssue(), request.mandatoryParam(PARAM_TRANSITION));
- responseWriter.write(issue, request, response);
+ SearchResponseData preloadedSearchResponseData = doTransition(dbSession, issueDto, request.mandatoryParam(PARAM_TRANSITION));
+ responseWriter.write(issue, preloadedSearchResponseData, request, response);
}
}
- private void doTransition(DbSession session, DefaultIssue defaultIssue, String transitionKey) {
+ private SearchResponseData doTransition(DbSession session, IssueDto issueDto, String transitionKey) {
+ DefaultIssue defaultIssue = issueDto.toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
transitionService.checkTransitionPermission(transitionKey, defaultIssue);
if (transitionService.doTransition(defaultIssue, context, transitionKey)) {
- issueUpdater.saveIssue(session, defaultIssue, context, null);
+ return issueUpdater.saveIssueAndPreloadSearchResponseData(session, defaultIssue, context, null);
}
+ return new SearchResponseData(issueDto);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
index 783e8fb4247..19a024fc56b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
import org.sonar.api.config.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
@@ -35,6 +36,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDbTester;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
@@ -105,6 +107,7 @@ public class DoTransitionActionTest {
new ServerIssueStorage(system2, new DefaultRuleFinder(dbClient, defaultOrganizationProvider), dbClient, issueIndexer), mock(NotificationManager.class));
private ComponentDto project;
private ComponentDto file;
+ private ArgumentCaptor<SearchResponseData> preloadedSearchResponseDataCaptor = ArgumentCaptor.forClass(SearchResponseData.class);
private WsAction underTest = new DoTransitionAction(dbClient, userSession, new IssueFinder(dbClient, userSession), issueUpdater, transitionService, responseWriter);
private WsActionTester tester = new WsActionTester(underTest);
@@ -123,7 +126,8 @@ public class DoTransitionActionTest {
call(issueDto.getKey(), "confirm");
- verify(responseWriter).write(eq(issueDto.getKey()), any(Request.class), any(Response.class));
+ verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+ verifyContentOfPreloadedSearchResponseData(issueDto);
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CONFIRMED);
}
@@ -194,4 +198,17 @@ public class DoTransitionActionTest {
return newDto(rule, file, project);
}
+ private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
+ SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue();
+ assertThat(preloadedSearchResponseData.getIssues())
+ .extracting(IssueDto::getKey)
+ .containsOnly(issue.getKey());
+ assertThat(preloadedSearchResponseData.getRules())
+ .extracting(RuleDefinitionDto::getKey)
+ .containsOnly(issue.getRuleKey());
+ assertThat(preloadedSearchResponseData.getComponents())
+ .extracting(ComponentDto::uuid)
+ .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
+ }
+
}