mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 09:24:34 -05:00
Improve extension store sync
This commit is contained in:
@@ -290,7 +290,7 @@ class ServerConfig(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.unwrapped() as? List<String>)
|
||||
?.map {
|
||||
if (it.contains("github")) {
|
||||
if (it.contains("github.com")) {
|
||||
it.replace(repoMatchRegex) {
|
||||
"https://raw.githubusercontent.com/${it.groupValues[2]}/${it.groupValues[3]}/" +
|
||||
(it.groupValues.getOrNull(4)?.ifBlank { null } ?: "repo") +
|
||||
@@ -304,7 +304,7 @@ class ServerConfig(
|
||||
},
|
||||
),
|
||||
readMigrated = { extensionStores.value },
|
||||
setMigrated = { extensionStores.value = it },
|
||||
setMigrated = { extensionStores.value = (extensionStores.value + it).distinct() },
|
||||
typeInfo =
|
||||
SettingsRegistry.PartialTypeInfo(
|
||||
specificType = "List<String>",
|
||||
@@ -1118,7 +1118,7 @@ class ServerConfig(
|
||||
val extensionStores: MutableStateFlow<List<String>> by ListSetting<String>(
|
||||
protoNumber = 97,
|
||||
group = SettingGroup.EXTENSION,
|
||||
privacySafe = false,
|
||||
privacySafe = true,
|
||||
defaultValue = emptyList(),
|
||||
itemValidator = { url ->
|
||||
if (url.isNotEmpty()) {
|
||||
@@ -1128,11 +1128,7 @@ class ServerConfig(
|
||||
}
|
||||
},
|
||||
itemToValidValue = { url ->
|
||||
if (url.isNotEmpty()) {
|
||||
url
|
||||
} else {
|
||||
null
|
||||
}
|
||||
url.ifEmpty { null }
|
||||
},
|
||||
typeInfo =
|
||||
SettingsRegistry.PartialTypeInfo(
|
||||
|
||||
@@ -134,7 +134,7 @@ object ExtensionStoreService {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq oldIndexUrl }
|
||||
}
|
||||
syncDbToPrefs()
|
||||
syncDbToPrefs(oldIndexUrl)
|
||||
}
|
||||
store
|
||||
} catch (e: Exception) {
|
||||
@@ -144,7 +144,7 @@ object ExtensionStoreService {
|
||||
}
|
||||
}
|
||||
|
||||
fun syncDbToPrefs() {
|
||||
fun syncDbToPrefs(keepRemoved: String? = null) {
|
||||
val dbStores =
|
||||
transaction {
|
||||
ExtensionStoreTable
|
||||
@@ -154,8 +154,8 @@ object ExtensionStoreService {
|
||||
}
|
||||
|
||||
val currentPrefs = serverConfig.extensionStores.value.toSet()
|
||||
val toAdd = dbStores - currentPrefs
|
||||
val toRemove = currentPrefs - dbStores
|
||||
val toAdd = (dbStores - currentPrefs - keepRemoved).filterNotNull()
|
||||
val toRemove = (currentPrefs - dbStores + keepRemoved).filterNotNull()
|
||||
|
||||
if (toAdd.isNotEmpty()) {
|
||||
serverConfig.extensionStores.value = (serverConfig.extensionStores.value + toAdd).distinct()
|
||||
@@ -180,6 +180,12 @@ object ExtensionStoreService {
|
||||
try {
|
||||
val store = fetch(url)
|
||||
upsert(store)
|
||||
if (store.indexUrl != url) {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq url }
|
||||
}
|
||||
syncDbToPrefs(url)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "Failed to sync preference store '$url' to database" }
|
||||
}
|
||||
|
||||
@@ -525,6 +525,7 @@ fun applicationSetup() {
|
||||
serverConfig.extensionStores,
|
||||
{ _ ->
|
||||
ExtensionStoreService.syncPrefsToDb()
|
||||
ExtensionStoreService.syncDbToPrefs()
|
||||
},
|
||||
ignoreInitialValue = false,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user