mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
Add mutex to "updateExtensionDatabase" (#829)
If called in quick succession it is possible that duplicated extensions get inserted to the database, because it has not yet been updated by the first call
This commit is contained in:
@@ -8,6 +8,8 @@ package suwayomi.tachidesk.manga.impl.extension
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.jetbrains.exposed.dao.id.EntityID
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
@@ -86,7 +88,10 @@ object ExtensionsList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateExtensionDatabase(foundExtensions: List<OnlineExtension>) {
|
private val updateExtensionDatabaseMutex = Mutex()
|
||||||
|
|
||||||
|
private suspend fun updateExtensionDatabase(foundExtensions: List<OnlineExtension>) {
|
||||||
|
updateExtensionDatabaseMutex.withLock {
|
||||||
transaction {
|
transaction {
|
||||||
val uniqueExtensions =
|
val uniqueExtensions =
|
||||||
foundExtensions.groupBy { it.pkgName }.mapValues {
|
foundExtensions.groupBy { it.pkgName }.mapValues {
|
||||||
@@ -200,6 +205,7 @@ object ExtensionsList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun String.repoUrlReplace(): String {
|
private fun String.repoUrlReplace(): String {
|
||||||
return if (contains("github")) {
|
return if (contains("github")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user