Remove caching of extensions for gql mutation (#806)

The client should use the extension query to get "cached" extensions and the mutation to update the extensions
This commit is contained in:
schroda
2024-01-10 01:38:21 +01:00
committed by GitHub
parent c70c860a82
commit 6376972130
@@ -34,30 +34,35 @@ object ExtensionsList {
var updateMap = ConcurrentHashMap<String, OnlineExtension>()
suspend fun fetchExtensions() {
// update if 60 seconds has passed or requested offline and database is empty
val extensions =
(listOf(ExtensionGithubApi.REPO_URL_PREFIX) + serverConfig.extensionRepos.value).map { repo ->
kotlin.runCatching {
ExtensionGithubApi.findExtensions(repo)
}.onFailure {
logger.warn(it) {
"Failed to fetch extensions for repo: $repo"
}
}
}
val foundExtensions = extensions.mapNotNull { it.getOrNull() }.flatten()
updateExtensionDatabase(foundExtensions)
}
suspend fun fetchExtensionsCached() {
// update if 60 seconds has passed or requested offline and database is empty
if (lastUpdateCheck + 60.seconds.inWholeMilliseconds < System.currentTimeMillis()) {
logger.debug("Getting extensions list from the internet")
lastUpdateCheck = System.currentTimeMillis()
val extensions =
(listOf(ExtensionGithubApi.REPO_URL_PREFIX) + serverConfig.extensionRepos.value).map { repo ->
kotlin.runCatching {
ExtensionGithubApi.findExtensions(repo)
}.onFailure {
logger.warn(it) {
"Failed to fetch extensions for repo: $repo"
}
}
}
val foundExtensions = extensions.mapNotNull { it.getOrNull() }.flatten()
updateExtensionDatabase(foundExtensions)
fetchExtensions()
} else {
logger.debug("used cached extension list")
}
}
suspend fun getExtensionList(): List<ExtensionDataClass> {
fetchExtensions()
fetchExtensionsCached()
return extensionTableAsDataClass()
}