]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5530 - Added methods to insert context objects
authorStephane Gamard <stephane.gamard@sonarsource.com>
Tue, 9 Sep 2014 11:59:52 +0000 (13:59 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Tue, 9 Sep 2014 11:59:52 +0000 (13:59 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResult.java
server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java

index eacb867b53c496b5116f433db0d35fdd82153793..d94a90de5081c85ffd2aca3491561f6e7eec8f0f 100644 (file)
@@ -25,6 +25,8 @@ import com.google.common.collect.HashMultiset;
 import com.google.common.collect.Multiset;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.search.SearchResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.issue.ActionPlan;
 import org.sonar.api.issue.Issue;
@@ -64,6 +66,7 @@ import org.sonar.server.search.QueryOptions;
 import org.sonar.server.user.UserSession;
 
 import javax.annotation.Nullable;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -77,6 +80,8 @@ import java.util.Set;
  */
 public class IssueService implements ServerComponent {
 
+  private static final Logger LOGGER = LoggerFactory.getLogger(IssueService.class);
+
   private final DbClient dbClient;
   private final IndexClient indexClient;
 
@@ -340,7 +345,6 @@ public class IssueService implements ServerComponent {
 
     IssueIndex issueIndex = indexClient.get(IssueIndex.class);
 
-    long t0 = System.currentTimeMillis();
     SearchResponse esResults = issueIndex.search(query, options);
 
     // Extend the content of the resultSet to make an actual IssueResponse
@@ -350,10 +354,7 @@ public class IssueService implements ServerComponent {
       (options.getOffset() * options.getLimit()) + 1,
       new Long(esResults.getHits().getTotalHits()).intValue()));
 
-    long t1 = System.currentTimeMillis();
-    long t2 = System.currentTimeMillis();
 
-    // TODO Optimise
     // Insert the projects and component name;
     Set<RuleKey> ruleKeys = new HashSet<RuleKey>();
     Set<String> projectKeys = new HashSet<String>();
@@ -372,14 +373,13 @@ public class IssueService implements ServerComponent {
 
     try {
       indexClient.get(RuleIndex.class).getByKeys(ruleKeys);
-      result.projects().addAll(dbClient.componentDao().getByKeys(session, projectKeys));
-      result.components().addAll(dbClient.componentDao().getByKeys(session, componentKeys));
-      dbClient.userDao().selectUsersByLogins(session, userLogins);
+      result.addProjects(dbClient.componentDao().getByKeys(session, projectKeys));
+      result.addComponents(dbClient.componentDao().getByKeys(session, componentKeys));
+   dbClient.userDao().selectUsersByLogins(session, userLogins);
       dbClient.actionPlanDao().findByKeys(actionPlanKeys);
     } finally {
       session.close();
     }
-    long t3 = System.currentTimeMillis();
 
     return result;
   }
index e01ccdee9d71b2a68d97a07d1d1ee9cdd9d9f1c5..052743306f377deea842025358d498c063279def 100644 (file)
@@ -136,23 +136,27 @@ public class IssueResult extends Result<IssueDoc> implements IssueQueryResult {
     return false;
   }
 
-  public void addProject(ComponentDto project) {
-    this.projects.put(project.key(), project);
+  public void addProjects(Collection<ComponentDto> projects) {
+    for (ComponentDto project : projects) {
+      this.projects.put(project.key(), project);
+    }
   }
 
-  public void addComponent(ComponentDto component) {
-    this.components.put(component.key(), component);
+  public void addComponents(Collection<ComponentDto> components) {
+    for (ComponentDto component : components) {
+      this.components.put(component.key(), component);
+ }
   }
 
-  public void addUser(User user) {
+  public void addUsers(User user) {
     this.usersByLogin.put(user.login(), user);
   }
 
-  public void addActionPlan(ActionPlan plan) {
+  public void addActionPlans(ActionPlan plan) {
     this.actionPlans.put(plan.key(), plan);
   }
 
-  public void addRule(Rule rule) {
+  public void addRules(Rule rule) {
     this.rules.put(rule.getKey(), rule);
   }
 }
index e5039c14c6b2ebbc82d32b8a5d58bfe666e0161a..948b5e8d8f816ba37397943a22f2d5854f6c4cb2 100644 (file)
@@ -412,13 +412,18 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
           .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
     }
 
-    MultiGetResponse response = client.execute(request);
-    if (response.getResponses() != null) {
-      for (MultiGetItemResponse item : response.getResponses()) {
-        results.add(toDoc(item.getResponse().getSource()));
+    try {
+      MultiGetResponse response = client.execute(request);
+      if (response.getResponses() != null) {
+        for (MultiGetItemResponse item : response.getResponses()) {
+          results.add(toDoc(item.getResponse().getSource()));
+        }
       }
+    } catch (Exception e) {
+      LOG.debug("could not multi-get.", e);
+    } finally {
+      return results;
     }
-    return results;
   }
 
   public Collection<DOMAIN> getByKeys(KEY... keys) {