mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 19:04:39 -05:00
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:
@@ -34,30 +34,35 @@ object ExtensionsList {
|
|||||||
var updateMap = ConcurrentHashMap<String, OnlineExtension>()
|
var updateMap = ConcurrentHashMap<String, OnlineExtension>()
|
||||||
|
|
||||||
suspend fun fetchExtensions() {
|
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
|
// update if 60 seconds has passed or requested offline and database is empty
|
||||||
if (lastUpdateCheck + 60.seconds.inWholeMilliseconds < System.currentTimeMillis()) {
|
if (lastUpdateCheck + 60.seconds.inWholeMilliseconds < System.currentTimeMillis()) {
|
||||||
logger.debug("Getting extensions list from the internet")
|
logger.debug("Getting extensions list from the internet")
|
||||||
lastUpdateCheck = System.currentTimeMillis()
|
lastUpdateCheck = System.currentTimeMillis()
|
||||||
|
|
||||||
val extensions =
|
fetchExtensions()
|
||||||
(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)
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug("used cached extension list")
|
logger.debug("used cached extension list")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getExtensionList(): List<ExtensionDataClass> {
|
suspend fun getExtensionList(): List<ExtensionDataClass> {
|
||||||
fetchExtensions()
|
fetchExtensionsCached()
|
||||||
return extensionTableAsDataClass()
|
return extensionTableAsDataClass()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user