mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
fix: re-sync (#2121)
This commit is contained in:
@@ -124,27 +124,30 @@ object ExtensionStoreService {
|
|||||||
transaction {
|
transaction {
|
||||||
ExtensionStoreTable.selectAll().toList()
|
ExtensionStoreTable.selectAll().toList()
|
||||||
}
|
}
|
||||||
return stores.mapNotNull { storeRow ->
|
var needsPrefUpdate = false
|
||||||
|
val updateStores = stores.mapNotNull { storeRow ->
|
||||||
val oldIndexUrl = storeRow[ExtensionStoreTable.indexUrl]
|
val oldIndexUrl = storeRow[ExtensionStoreTable.indexUrl]
|
||||||
val oldName = storeRow[ExtensionStoreTable.name]
|
val oldName = storeRow[ExtensionStoreTable.name]
|
||||||
try {
|
try {
|
||||||
val store = fetch(oldIndexUrl)
|
val store = fetch(oldIndexUrl)
|
||||||
upsert(store)
|
|
||||||
if (store.indexUrl != oldIndexUrl) {
|
if (store.indexUrl != oldIndexUrl) {
|
||||||
transaction {
|
transaction {
|
||||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq oldIndexUrl }
|
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq oldIndexUrl }
|
||||||
}
|
}
|
||||||
syncDbToPrefs(oldIndexUrl)
|
needsPrefUpdate = true
|
||||||
}
|
}
|
||||||
|
upsert(store)
|
||||||
store
|
store
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.warn(e) { "Failed to fetch extension store '$oldName ($oldIndexUrl)'" }
|
logger.warn(e) { "Failed to fetch extension store '$oldName ($oldIndexUrl)'" }
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (needsPrefUpdate) syncDbToPrefs()
|
||||||
|
return updateStores
|
||||||
}
|
}
|
||||||
|
|
||||||
fun syncDbToPrefs(keepRemoved: String? = null) {
|
fun syncDbToPrefs() {
|
||||||
val dbStores =
|
val dbStores =
|
||||||
transaction {
|
transaction {
|
||||||
ExtensionStoreTable
|
ExtensionStoreTable
|
||||||
@@ -154,8 +157,8 @@ object ExtensionStoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val currentPrefs = serverConfig.extensionStores.value.toSet()
|
val currentPrefs = serverConfig.extensionStores.value.toSet()
|
||||||
val toAdd = (dbStores - currentPrefs - keepRemoved).filterNotNull()
|
val toAdd = dbStores - currentPrefs
|
||||||
val toRemove = (currentPrefs - dbStores + keepRemoved).filterNotNull()
|
val toRemove = currentPrefs - dbStores
|
||||||
|
|
||||||
if (toAdd.isNotEmpty()) {
|
if (toAdd.isNotEmpty()) {
|
||||||
serverConfig.extensionStores.value = (serverConfig.extensionStores.value + toAdd).distinct()
|
serverConfig.extensionStores.value = (serverConfig.extensionStores.value + toAdd).distinct()
|
||||||
@@ -175,28 +178,33 @@ object ExtensionStoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val toAdd = prefUrls - dbStores.keys
|
val toAdd = prefUrls - dbStores.keys
|
||||||
|
val toRemove = (dbStores.keys - prefUrls).toMutableSet()
|
||||||
|
var needsPrefUpdate = toRemove.isNotEmpty()
|
||||||
|
|
||||||
toAdd.forEach { url ->
|
toAdd.forEach { url ->
|
||||||
try {
|
try {
|
||||||
val store = fetch(url)
|
val store = fetch(url)
|
||||||
upsert(store)
|
|
||||||
if (store.indexUrl != url) {
|
if (store.indexUrl != url) {
|
||||||
transaction {
|
transaction {
|
||||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq url }
|
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq url }
|
||||||
}
|
}
|
||||||
syncDbToPrefs(url)
|
needsPrefUpdate = true
|
||||||
|
toRemove -= store.indexUrl
|
||||||
}
|
}
|
||||||
|
upsert(store)
|
||||||
} 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" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val toRemove = dbStores.keys - prefUrls
|
|
||||||
if (toRemove.isNotEmpty()) {
|
if (toRemove.isNotEmpty()) {
|
||||||
transaction {
|
transaction {
|
||||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl inList toRemove.toList() }
|
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl inList toRemove.toList() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (needsPrefUpdate) {
|
||||||
|
syncDbToPrefs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getExtensions(store: ExtensionStore): List<ExtensionInfo> {
|
suspend fun getExtensions(store: ExtensionStore): List<ExtensionInfo> {
|
||||||
|
|||||||
@@ -525,7 +525,6 @@ fun applicationSetup() {
|
|||||||
serverConfig.extensionStores,
|
serverConfig.extensionStores,
|
||||||
{ _ ->
|
{ _ ->
|
||||||
ExtensionStoreService.syncPrefsToDb()
|
ExtensionStoreService.syncPrefsToDb()
|
||||||
ExtensionStoreService.syncDbToPrefs()
|
|
||||||
},
|
},
|
||||||
ignoreInitialValue = false,
|
ignoreInitialValue = false,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user