Skip to content

Commit 062198c

Browse files
authored
Merge pull request #87 from dwasinge/perf
GET All Engagements - Performance Improvements Part 1: Use Parallel Stream
2 parents cdf88ff + 3929f45 commit 062198c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/main/java/com/redhat/labs/omp/service/EngagementService.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.Optional;
7+
import java.util.stream.Collectors;
78

89
import javax.annotation.PostConstruct;
910
import javax.enterprise.context.ApplicationScoped;
@@ -178,19 +179,20 @@ public List<Engagement> getAllEngagements() {
178179

179180
List<Project> projects = projectService.getProjectsByGroup(engagementRepositoryId, true);
180181

181-
List<Engagement> engagementList = new ArrayList<>();
182+
return
183+
projects
184+
.parallelStream()
185+
.map(project -> {
186+
return getEngagement(project, true);
187+
})
188+
.filter(optional -> optional.isPresent())
189+
.map(optional -> {
190+
return optional.get();
191+
})
192+
.collect(Collectors.toList());
182193

183-
for (Project project : projects) {
184-
LOGGER.debug("project id {}", project.getId());
185-
Optional<Engagement> engagement = getEngagement(project, true);
186-
if(engagement.isPresent() ) {
187-
engagementList.add(engagement.get());
188-
}
189-
}
190-
191-
return engagementList;
192194
}
193-
195+
194196
public Engagement getEngagement(String namespaceOrId, boolean includeStatus) {
195197
Engagement engagement = null;
196198

0 commit comments

Comments
 (0)