]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6940 tracking: do not query FILE_SOURCE for non-FILE components 763/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 3 Feb 2016 17:19:30 +0000 (18:19 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 4 Feb 2016 16:41:47 +0000 (17:41 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerBaseInputFactory.java

index c7cf943561b3305f48e15047a4c2159ec70a5f2c..55da6dccd9e715f3591e470914d968518c7fac20 100644 (file)
  */
 package org.sonar.server.computation.issue;
 
-import com.google.common.base.Objects;
 import java.util.Collections;
 import java.util.List;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.tracking.Input;
 import org.sonar.core.issue.tracking.LazyInput;
 import org.sonar.core.issue.tracking.LineHashSequence;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.computation.component.Component;
-import org.sonar.db.DbClient;
 
 /**
  * Factory of {@link Input} of base data for issue tracking. Data are lazy-loaded.
  */
 public class TrackerBaseInputFactory {
+  private static final LineHashSequence EMPTY_LINE_HASH_SEQUENCE = new LineHashSequence(Collections.<String>emptyList());
 
   private final BaseIssuesLoader baseIssuesLoader;
   private final DbClient dbClient;
@@ -57,10 +57,17 @@ public class TrackerBaseInputFactory {
 
     @Override
     protected LineHashSequence loadLineHashSequence() {
+      if (component.getType() != Component.Type.FILE) {
+        return EMPTY_LINE_HASH_SEQUENCE;
+      }
+      
       DbSession session = dbClient.openSession(false);
       try {
         List<String> hashes = dbClient.fileSourceDao().selectLineHashes(session, component.getUuid());
-        return new LineHashSequence(Objects.firstNonNull(hashes, Collections.<String>emptyList()));
+        if (hashes == null || hashes.isEmpty()) {
+          return EMPTY_LINE_HASH_SEQUENCE;
+        }
+        return new LineHashSequence(hashes);
       } finally {
         MyBatis.closeQuietly(session);
       }