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;
import org.sonar.server.user.UserSession;
import javax.annotation.Nullable;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
*/
public class IssueService implements ServerComponent {
+ private static final Logger LOGGER = LoggerFactory.getLogger(IssueService.class);
+
private final DbClient dbClient;
private final IndexClient indexClient;
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
(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>();
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;
}
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);
}
}
.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) {