Skip to content

Commit c852592

Browse files
authored
Prevent adding duplicated extensions to the db table (#808)
* Prevent adding duplicated extensions to the db table There is a possibility that multiple extension repos have been added which contain the same extensions. In case these extensions have not been added to the db table yet, they would all get added to the db, which would create duplicated extensions * Use the extension with the latest version from all repos In case multiple repos have the same extension, use the extension with the latest version
1 parent 3a1e0c5 commit c852592

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/src/main/kotlin/suwayomi/tachidesk/manga/impl/extension/ExtensionsList.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,21 @@ object ExtensionsList {
8888

8989
private fun updateExtensionDatabase(foundExtensions: List<OnlineExtension>) {
9090
transaction {
91+
val uniqueExtensions =
92+
foundExtensions.groupBy { it.pkgName }.mapValues {
93+
(_, extension) ->
94+
extension.maxBy { it.versionCode }
95+
}.values
9196
val installedExtensions =
9297
ExtensionTable.selectAll().toList()
9398
.associateBy { it[ExtensionTable.pkgName] }
9499
val extensionsToUpdate = mutableListOf<Pair<OnlineExtension, ResultRow>>()
95100
val extensionsToInsert = mutableListOf<OnlineExtension>()
96101
val extensionsToDelete =
97102
installedExtensions.filter { it.value[ExtensionTable.repo] != null }.mapNotNull { (pkgName, extension) ->
98-
extension.takeUnless { foundExtensions.any { it.pkgName == pkgName } }
103+
extension.takeUnless { uniqueExtensions.any { it.pkgName == pkgName } }
99104
}
100-
foundExtensions.forEach {
105+
uniqueExtensions.forEach {
101106
val extension = installedExtensions[it.pkgName]
102107
if (extension != null) {
103108
extensionsToUpdate.add(it to extension)

0 commit comments

Comments
 (0)