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:
schroda
2024-01-21 01:42:01 +01:00
committed by GitHub
parent 57d5bc6480
commit d8876cf96a

View File

@@ -8,6 +8,8 @@ package suwayomi.tachidesk.manga.impl.extension
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import eu.kanade.tachiyomi.source.local.LocalSource
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import mu.KotlinLogging
import org.jetbrains.exposed.dao.id.EntityID
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 {
val uniqueExtensions =
foundExtensions.groupBy { it.pkgName }.mapValues {
@@ -200,6 +205,7 @@ object ExtensionsList {
}
}
}
}
private fun String.repoUrlReplace(): String {
return if (contains("github")) {