]> source.dussan.org Git - sonarqube.git/commitdiff
Computation stack must not update issues in db if no fields were changed
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 12:15:31 +0000 (13:15 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 12:15:31 +0000 (13:15 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java

index e64ce2c590f91b5d2b97ed254e99b9093510a887..d081874346a249509d6a20e75ba429ade0a57882 100644 (file)
@@ -67,34 +67,36 @@ public class PersistIssuesStep implements ComputationStep {
     try {
       while (issues.hasNext()) {
         DefaultIssue issue = issues.next();
-
+        boolean saved = false;
         if (issue.isNew()) {
           Integer ruleId = ruleCache.get(issue.ruleKey()).getId();
           mapper.insert(IssueDto.toDtoForBatchInsert(issue, issue.componentId(), context.getProject().getId(), ruleId, system2.now()));
           count++;
-        } else {
+          saved = true;
+        } else if (issue.isChanged()) {
           IssueDto dto = IssueDto.toDtoForUpdate(issue, context.getProject().getId(), system2.now());
           if (Issue.STATUS_CLOSED.equals(issue.status()) || issue.selectedAt() == null) {
             // Issue is closed by scan or changed by end-user
             mapper.update(dto);
-
+            count++;
           } else {
             int updateCount = mapper.updateIfBeforeSelectedDate(dto);
+            count++;
             if (updateCount == 0) {
               // End-user and scan changed the issue at the same time.
               // See https://jira.codehaus.org/browse/SONAR-4309
               conflictResolver.resolve(issue, mapper);
             }
           }
-
-          count++;
+          saved = true;
         }
-        count += insertChanges(changeMapper, issue);
-
-        if (count > BatchSession.MAX_BATCH_SIZE) {
-          session.flushStatements();
-          session.commit();
-          count = 0;
+        if (saved) {
+          count += insertChanges(changeMapper, issue);
+          if (count > BatchSession.MAX_BATCH_SIZE) {
+            session.flushStatements();
+            session.commit();
+            count = 0;
+          }
         }
       }
       session.flushStatements();