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