|
52 | 52 | import org.springframework.http.ResponseEntity;
|
53 | 53 | import org.springframework.stereotype.Component;
|
54 | 54 | import org.springframework.util.Assert;
|
| 55 | +import org.springframework.util.ConcurrentReferenceHashMap; |
55 | 56 | import org.springframework.web.client.HttpStatusCodeException;
|
56 | 57 |
|
57 | 58 | /**
|
@@ -82,6 +83,8 @@ public class GitHub extends GitHubSupport implements IssueTracker {
|
82 | 83 | private static final ParameterizedTypeReference<GitHubWorkflows> WORKFLOWS_TYPE = new ParameterizedTypeReference<GitHubWorkflows>() {};
|
83 | 84 | private static final Map<TicketType, Label> TICKET_LABELS = new HashMap<>();
|
84 | 85 |
|
| 86 | + private final Map<ModuleIteration, Optional<Milestone>> milestoneCache = new ConcurrentReferenceHashMap<>(); |
| 87 | + |
85 | 88 | static {
|
86 | 89 |
|
87 | 90 | TICKET_LABELS.put(TicketType.Task, LabelConfiguration.TYPE_TASK);
|
@@ -210,7 +213,7 @@ public void createReleaseVersion(ModuleIteration moduleIteration) {
|
210 | 213 | Assert.notNull(moduleIteration, "ModuleIteration must not be null.");
|
211 | 214 |
|
212 | 215 | String repositoryName = GitProject.of(moduleIteration.getProject()).getRepositoryName();
|
213 |
| - Optional<Milestone> milestone = findMilestone(moduleIteration, repositoryName); |
| 216 | + Optional<Milestone> milestone = findMilestone(moduleIteration); |
214 | 217 |
|
215 | 218 | if (milestone.isPresent()) {
|
216 | 219 | return;
|
@@ -269,7 +272,7 @@ private Ticket doCreateTicket(ModuleIteration moduleIteration, String text, Tick
|
269 | 272 | boolean assignToCurrentUser) {
|
270 | 273 |
|
271 | 274 | String repositoryName = GitProject.of(moduleIteration.getProject()).getRepositoryName();
|
272 |
| - Milestone milestone = getMilestone(moduleIteration, repositoryName); |
| 275 | + Milestone milestone = getMilestone(moduleIteration); |
273 | 276 |
|
274 | 277 | Label label = TICKET_LABELS.get(ticketType);
|
275 | 278 |
|
@@ -381,8 +384,22 @@ private Map<String, Object> newUrlTemplateVariables() {
|
381 | 384 | return parameters;
|
382 | 385 | }
|
383 | 386 |
|
384 |
| - private Optional<Milestone> findMilestone(ModuleIteration moduleIteration, String repositoryName) { |
385 |
| - return doFindMilestone(moduleIteration, repositoryName, m -> m.matches(moduleIteration)); |
| 387 | + private Optional<Milestone> findMilestone(ModuleIteration moduleIteration) { |
| 388 | + |
| 389 | + // we're inside a cacheable object, so we cannot reuse Spring Caching for inner method calls. |
| 390 | + Optional<Milestone> milestone = milestoneCache.get(moduleIteration); |
| 391 | + if (milestone == null) { |
| 392 | + |
| 393 | + String repositoryName = GitProject.of(moduleIteration.getProject()).getRepositoryName(); |
| 394 | + milestone = doFindMilestone(moduleIteration, repositoryName, m -> m.matches(moduleIteration)); |
| 395 | + |
| 396 | + if(milestone.isPresent()) { |
| 397 | + milestoneCache.put(moduleIteration, milestone); |
| 398 | + } |
| 399 | + } |
| 400 | + |
| 401 | + return milestone; |
| 402 | + |
386 | 403 | }
|
387 | 404 |
|
388 | 405 | private Optional<Milestone> doFindMilestone(ModuleIteration moduleIteration, String repositoryName,
|
@@ -445,7 +462,7 @@ public void closeIteration(ModuleIteration module) {
|
445 | 462 |
|
446 | 463 | GitProject project = GitProject.of(module.getProject());
|
447 | 464 |
|
448 |
| - findMilestone(module, project.getRepositoryName()) // |
| 465 | + findMilestone(module) // |
449 | 466 | .filter(Milestone::isOpen) //
|
450 | 467 | .map(Milestone::markReleased) //
|
451 | 468 | .ifPresent(milestone -> {
|
@@ -749,7 +766,7 @@ private Stream<GitHubReadIssue> getIssuesFor(ModuleIteration moduleIteration, bo
|
749 | 766 |
|
750 | 767 | String repositoryName = GitProject.of(moduleIteration.getProject()).getRepositoryName();
|
751 | 768 |
|
752 |
| - Optional<Milestone> optionalMilestone = findMilestone(moduleIteration, repositoryName); |
| 769 | + Optional<Milestone> optionalMilestone = findMilestone(moduleIteration); |
753 | 770 |
|
754 | 771 | if (ignoreMissingMilestone && !optionalMilestone.isPresent()) {
|
755 | 772 | return Stream.empty();
|
@@ -781,9 +798,9 @@ private Stream<GitHubReadIssue> getForIssues(String template, Map<String, Object
|
781 | 798 | return issues.stream();
|
782 | 799 | }
|
783 | 800 |
|
784 |
| - private Milestone getMilestone(ModuleIteration moduleIteration, String repositoryName) { |
| 801 | + private Milestone getMilestone(ModuleIteration moduleIteration) { |
785 | 802 |
|
786 |
| - Optional<Milestone> milestone = findMilestone(moduleIteration, repositoryName); |
| 803 | + Optional<Milestone> milestone = findMilestone(moduleIteration); |
787 | 804 |
|
788 | 805 | return milestone.orElseThrow(() -> noSuchMilestone(moduleIteration));
|
789 | 806 | }
|
|
0 commit comments