From d00874c660c7c4a3ac1964220b83cd475a653c3f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 29 Oct 2014 21:46:28 +0100 Subject: [PATCH] SONAR-5375 Minor optimization to remove all issues once for a given component --- .../core/issue/IssueTrackingDecorator.java | 23 +++++++++++-------- .../org/sonar/batch/issue/IssueCache.java | 5 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java index f46e87baf76..27ee9a8ca6f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java @@ -25,7 +25,12 @@ import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.batch.*; +import org.sonar.api.batch.Decorator; +import org.sonar.api.batch.DecoratorBarriers; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.batch.DependedUpon; +import org.sonar.api.batch.DependsUpon; +import org.sonar.api.batch.SonarIndex; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; @@ -69,13 +74,13 @@ public class IssueTrackingDecorator implements Decorator { private final RuleFinder ruleFinder; public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking, - LastSnapshots lastSnapshots, SonarIndex index, - IssueHandlers handlers, IssueWorkflow workflow, - IssueUpdater updater, - Project project, - ResourcePerspectives perspectives, - RulesProfile rulesProfile, - RuleFinder ruleFinder) { + LastSnapshots lastSnapshots, SonarIndex index, + IssueHandlers handlers, IssueWorkflow workflow, + IssueUpdater updater, + Project project, + ResourcePerspectives perspectives, + RulesProfile rulesProfile, + RuleFinder ruleFinder) { this.issueCache = issueCache; this.initialOpenIssues = initialOpenIssues; this.tracking = tracking; @@ -107,9 +112,9 @@ public class IssueTrackingDecorator implements Decorator { void doDecorate(Resource resource) { Collection issues = Lists.newArrayList(); for (Issue issue : issueCache.byComponent(resource.getEffectiveKey())) { - issueCache.remove(issue); issues.add((DefaultIssue) issue); } + issueCache.removeAll(resource.getEffectiveKey()); // issues = all the issues created by rule engines during this module scan and not excluded by filters // all the issues that are not closed in db before starting this module scan, including manual issues diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java index b0d56d5957d..7fd894bca6e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java @@ -20,7 +20,6 @@ package org.sonar.batch.issue; import org.sonar.api.BatchComponent; -import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.batch.index.Cache; import org.sonar.batch.index.Caches; @@ -50,7 +49,7 @@ public class IssueCache implements BatchComponent { return this; } - public boolean remove(Issue issue) { - return cache.remove(issue.componentKey(), issue.key()); + public boolean removeAll(String componentKey) { + return cache.remove(componentKey); } } -- 2.39.5