diff --git a/package-search-api-models b/package-search-api-models index 7e81796c..54dd8be6 160000 --- a/package-search-api-models +++ b/package-search-api-models @@ -1 +1 @@ -Subproject commit 7e81796c95d0b6a6943fa89378ae5b1d0cf6a688 +Subproject commit 54dd8be6338ed751da6ffee29bc3e245590aa2e9 diff --git a/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/services/PackageSearchApplicationCachesService.kt b/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/services/PackageSearchApplicationCachesService.kt index 9c97cfac..86ba209f 100644 --- a/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/services/PackageSearchApplicationCachesService.kt +++ b/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/services/PackageSearchApplicationCachesService.kt @@ -26,7 +26,7 @@ import io.ktor.client.engine.java.Java import io.ktor.client.plugins.DefaultRequest import io.ktor.client.plugins.logging.LogLevel import io.ktor.client.plugins.logging.Logging -import io.ktor.http.headers +import io.ktor.client.request.headers import java.util.concurrent.CompletableFuture import kotlin.io.path.absolutePathString import kotlin.io.path.div diff --git a/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/utils/PackageSearchApiPackageCache.kt b/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/utils/PackageSearchApiPackageCache.kt index 011ba69d..09dcb5d9 100644 --- a/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/utils/PackageSearchApiPackageCache.kt +++ b/plugin/src/main/kotlin/com/jetbrains/packagesearch/plugin/utils/PackageSearchApiPackageCache.kt @@ -4,6 +4,7 @@ import com.jetbrains.packagesearch.plugin.core.nitrite.NitriteFilters import com.jetbrains.packagesearch.plugin.core.nitrite.coroutines.CoroutineObjectRepository import com.jetbrains.packagesearch.plugin.core.nitrite.insert import com.jetbrains.packagesearch.plugin.core.utils.suspendSafe +import io.ktor.client.request.HttpRequestBuilder import korlibs.crypto.SHA256 import kotlin.random.Random import kotlin.time.Duration @@ -32,19 +33,28 @@ class PackageSearchApiPackageCache( private val cachesMutex = Mutex() - override suspend fun getPackageInfoByIds(ids: Set) = + override suspend fun getPackageInfoByIds( + ids: Set, + requestBuilder: (HttpRequestBuilder.() -> Unit)?, + ): Map = getPackages( ids = ids, useHashes = false ) - override suspend fun getPackageInfoByIdHashes(ids: Set): Map = + override suspend fun getPackageInfoByIdHashes( + ids: Set, + requestBuilder: (HttpRequestBuilder.() -> Unit)?, + ): Map = getPackages( ids = ids, useHashes = true ) - override suspend fun searchPackages(request: SearchPackagesRequest): List { + override suspend fun searchPackages( + request: SearchPackagesRequest, + requestBuilder: (HttpRequestBuilder.() -> Unit)?, + ): List { val sha = SHA256.digest(Json.encodeToString(request).toByteArray()).base64 val contextName = "${Random.nextInt()} | ${this::class}#searchPackages" logDebug(contextName) { "Searching for packages | searchSha = $sha" } @@ -66,7 +76,7 @@ class PackageSearchApiPackageCache( .also { searchCache.insert(ApiSearchEntry(it, sha, request)) } } - override suspend fun getKnownRepositories(): List { + override suspend fun getKnownRepositories(requestBuilder: (HttpRequestBuilder.() -> Unit)?): List { val cached = repositoryCache.find().singleOrNull() val isOnlineStatus = isOnline() if (cached != null && (Clock.System.now() < cached.lastUpdate + maxAge || !isOnlineStatus)) { @@ -129,7 +139,7 @@ class PackageSearchApiPackageCache( else -> { // retrieve the packages from the network - val networkResults = runCatching { apiCall(missingIds) } + val networkResults = runCatching { apiCall(missingIds, null) } .suspendSafe() .onFailure { logDebug("${this::class.qualifiedName}#getPackages", it) } if (networkResults.isSuccess) {