aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-05 17:22:37 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-09 10:09:44 +0200
commit79c9df10e439d6b3ddeeb0a07e3b027dc1460919 (patch)
treec68ccb12c1def526b24982906ca4792209d4ed57 /server/sonar-server
parent71a8cb1e5fd5edcf8b96539c4f49e7648fc1adbd (diff)
downloadsonarqube-79c9df10e439d6b3ddeeb0a07e3b027dc1460919.tar.gz
sonarqube-79c9df10e439d6b3ddeeb0a07e3b027dc1460919.zip
SONAR-8061 speed up set issue type removing duplicate SQ
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java19
2 files changed, 26 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
index 4fde4097328..0c68784f034 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
@@ -31,6 +31,7 @@ import org.sonar.core.issue.IssueChangeContext;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.issue.IssueDto;
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.IssueFinder;
import org.sonar.server.issue.IssueUpdater;
@@ -94,19 +95,21 @@ public class SetTypeAction implements IssuesWsAction {
String issueKey = request.mandatoryParam(PARAM_ISSUE);
RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE));
try (DbSession session = dbClient.openSession(false)) {
- setType(session, issueKey, ruleType);
+ SearchResponseData preloadedSearchResponseData = setType(session, issueKey, ruleType);
+ responseWriter.write(issueKey, preloadedSearchResponseData, request, response);
}
- responseWriter.write(issueKey, request, response);
}
- private void setType(DbSession session, String issueKey, RuleType ruleType) {
- DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
+ private SearchResponseData setType(DbSession session, String issueKey, RuleType ruleType) {
+ IssueDto issueDto = issueFinder.getByKey(session, issueKey);
+ DefaultIssue issue = issueDto.toDefaultIssue();
userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
if (issueFieldsSetter.setType(issue, ruleType, context)) {
- issueUpdater.saveIssue(session, issue, context, null);
+ return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null);
}
+ return new SearchResponseData(issueDto);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
index ea5b11160a9..bc492ea7be5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
@@ -24,6 +24,7 @@ import javax.annotation.Nullable;
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.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
@@ -87,6 +89,7 @@ public class SetTypeActionTest {
private IssueDbTester issueDbTester = new IssueDbTester(dbTester);
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
private OperationResponseWriter responseWriter = mock(OperationResponseWriter.class);
+ private ArgumentCaptor<SearchResponseData> preloadedSearchResponseDataCaptor = ArgumentCaptor.forClass(SearchResponseData.class);
private IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
private WsActionTester tester = new WsActionTester(new SetTypeAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
@@ -101,7 +104,8 @@ public class SetTypeActionTest {
call(issueDto.getKey(), BUG.name());
- 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.getType()).isEqualTo(BUG.getDbConstant());
}
@@ -190,4 +194,17 @@ public class SetTypeActionTest {
private void logInAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
}
+
+ 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());
+ }
}