Skip to content

Commit

Permalink
Remove caching of extensions for gql mutation (#806)
Browse files Browse the repository at this point in the history
The client should use the extension query to get "cached" extensions and the mutation to update the extensions
  • Loading branch information
schroda authored Jan 10, 2024
1 parent c70c860 commit 6376972
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 6376972

Please sign in to comment.