File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed
jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver
maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,17 @@ import io.ktor.server.routing.route
2424import io.micrometer.core.instrument.Tag
2525import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics
2626import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
27+ import kotlinx.coroutines.CoroutineScope
28+ import kotlinx.coroutines.Dispatchers
29+ import kotlinx.coroutines.launch
2730import kotlin.time.Duration.Companion.hours
2831
2932private val logger = logger { }
3033
3134typealias ArtifactResult = Result <Map <String , Artifact >>
3235
36+ private val prefetchScope = CoroutineScope (Dispatchers .IO )
37+
3338private val bindingsCache =
3439 Caffeine
3540 .newBuilder()
@@ -98,6 +103,12 @@ private fun Route.getArtifact(
98103 }
99104}
100105
106+ internal fun prefetchBindingArtifacts (coords : Collection <ActionCoords >) {
107+ prefetchScope.launch {
108+ bindingsCache.getAll(coords)
109+ }
110+ }
111+
101112private suspend fun ApplicationCall.toBindingArtifacts (refresh : Boolean ): Map <String , Artifact >? {
102113 val actionCoords = parameters.extractActionCoords(extractVersion = true )
103114
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ private val metadataCache =
2828 .recordStats()
2929 .asLoadingCache<ActionCoords , MetadataResult > {
3030 runCatching {
31- it.buildPackageArtifacts(githubAuthToken = getGithubAuthToken())
31+ it.buildPackageArtifacts(githubAuthToken = getGithubAuthToken(), ::prefetchBindingArtifacts )
3232 }
3333 }
3434
Original file line number Diff line number Diff line change @@ -18,13 +18,15 @@ internal suspend fun ActionCoords.buildMavenMetadataFile(
1818 name: String ,
1919 githubAuthToken: String? ,
2020 ) -> Either <String , List <Version >> = ::fetchAvailableVersions,
21+ prefetchBindingArtifacts : (Collection <ActionCoords >) -> Unit = {},
2122): String? {
2223 val availableVersions =
2324 fetchAvailableVersions(owner, name, githubAuthToken)
2425 .getOrElse {
2526 logger.error { it }
2627 emptyList()
2728 }.filter { it.isMajorVersion() || (significantVersion < FULL ) }
29+ prefetchBindingArtifacts(availableVersions.map { copy(version = " $it " ) })
2830 val newest = availableVersions.maxOrNull() ? : return null
2931 val lastUpdated =
3032 DateTimeFormatter
Original file line number Diff line number Diff line change @@ -2,8 +2,15 @@ package io.github.typesafegithub.workflows.mavenbinding
22
33import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
44
5- suspend fun ActionCoords.buildPackageArtifacts (githubAuthToken : String ): Map <String , String > {
6- val mavenMetadata = buildMavenMetadataFile(githubAuthToken = githubAuthToken) ? : return emptyMap()
5+ suspend fun ActionCoords.buildPackageArtifacts (
6+ githubAuthToken : String ,
7+ prefetchBindingArtifacts : (Collection <ActionCoords >) -> Unit ,
8+ ): Map <String , String > {
9+ val mavenMetadata =
10+ buildMavenMetadataFile(
11+ githubAuthToken = githubAuthToken,
12+ prefetchBindingArtifacts = prefetchBindingArtifacts,
13+ ) ? : return emptyMap()
714 return mapOf (
815 " maven-metadata.xml" to mavenMetadata,
916 " maven-metadata.xml.md5" to mavenMetadata.md5Checksum(),
You can’t perform that action at this time.
0 commit comments