Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit fa53948

Browse files
xloypaypakevinlzw
authored andcommitted
use thread pool to fetch branch commit
1 parent 548b8ad commit fa53948

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

backend/src/main/kotlin/metrik/project/domain/service/githubactions/PipelineCommitService.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ import java.time.Instant
1111
import java.time.ZoneOffset
1212
import java.time.ZonedDateTime
1313
import java.time.temporal.ChronoUnit
14+
import java.util.concurrent.Executors
15+
import java.util.concurrent.FutureTask
1416
import java.util.concurrent.atomic.AtomicInteger
1517

1618
@Service("githubActionsPipelineCommitsService")
1719
class PipelineCommitService(
1820
private val buildRepository: BuildRepository,
1921
private val commitService: CommitService
2022
) {
23+
private val defaultNumberOfBranchFetchConcurrency = 10
24+
private val executorService = Executors.newFixedThreadPool(defaultNumberOfBranchFetchConcurrency)
25+
2126
fun mapCommitToRun(
2227
pipeline: PipelineConfiguration,
2328
runs: MutableList<GithubActionsRun>,
@@ -28,8 +33,9 @@ class PipelineCommitService(
2833
val numberOfBranches = runsGroupedByBranch.size
2934
val progressCounter = AtomicInteger(0)
3035

31-
runsGroupedByBranch
32-
.forEach { (branch, run) ->
36+
val taskMap: MutableMap<String, FutureTask<Map<GithubActionsRun, List<Commit>>>> = mutableMapOf()
37+
runsGroupedByBranch.forEach { (branch, run) ->
38+
val branchTask = FutureTask {
3339
emitCb(
3440
SyncProgress(
3541
pipeline.id,
@@ -40,8 +46,15 @@ class PipelineCommitService(
4046
GithubActionConstants.totalNumberOfSteps,
4147
)
4248
)
43-
branchCommitsMap[branch] = mapRunToCommits(pipeline, run)
49+
mapRunToCommits(pipeline, run)
4450
}
51+
taskMap[branch] = branchTask
52+
executorService.submit(branchTask)
53+
}
54+
runsGroupedByBranch.forEach { (branch, _) ->
55+
branchCommitsMap[branch] = taskMap[branch]!!.get()
56+
}
57+
4558
return branchCommitsMap.toMap()
4659
}
4760

0 commit comments

Comments
 (0)