1
1
namespace Cake . Issues ;
2
2
3
- using System . Collections . Concurrent ;
4
3
using System . Collections . Generic ;
5
4
using System . Diagnostics ;
6
5
using System . Linq ;
@@ -46,12 +45,12 @@ public IEnumerable<IIssue> ReadIssues()
46
45
{
47
46
var stopwatch = Stopwatch . StartNew ( ) ;
48
47
49
- // Use thread-safe collection for collecting results
50
- var allIssues = new ConcurrentBag < IIssue > ( ) ;
48
+ var results = new List < IIssue > [ this . issueProviders . Count ] ;
51
49
52
50
// Process providers in parallel
53
- _ = Parallel . ForEach ( this . issueProviders , issueProvider =>
51
+ _ = Parallel . For ( 0 , this . issueProviders . Count , i =>
54
52
{
53
+ var issueProvider = this . issueProviders [ i ] ;
55
54
var providerName = issueProvider . GetType ( ) . Name ;
56
55
this . log . Verbose ( "Initialize issue provider {0}..." , providerName ) ;
57
56
@@ -76,21 +75,18 @@ public IEnumerable<IIssue> ReadIssues()
76
75
}
77
76
} ) ;
78
77
79
- // Add to thread-safe collection
80
- foreach ( var issue in currentIssues )
81
- {
82
- allIssues . Add ( issue ) ;
83
- }
78
+ results [ i ] = currentIssues ;
84
79
}
85
80
else
86
81
{
87
82
this . log . Warning ( "Error initializing issue provider {0}." , providerName ) ;
83
+ results [ i ] = [ ] ;
88
84
}
89
85
} ) ;
90
86
91
87
stopwatch . Stop ( ) ;
92
88
93
- var issuesList = allIssues . ToList ( ) ;
89
+ var issuesList = results . SelectMany ( r => r ) . ToList ( ) ;
94
90
this . log . Verbose (
95
91
"Reading {0} issues from {1} providers took {2} ms" ,
96
92
issuesList . Count ,
0 commit comments