Skip to content

Commit

Permalink
Prevent adding duplicated extensions to the db table
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schroda committed Jan 9, 2024
1 parent c70c860 commit 02a7827
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ object ExtensionsList {

private fun updateExtensionDatabase(foundExtensions: List<OnlineExtension>) {
transaction {
val uniqueExtensions = foundExtensions.distinctBy { it.pkgName }
val installedExtensions =
ExtensionTable.selectAll().toList()
.associateBy { it[ExtensionTable.pkgName] }
val extensionsToUpdate = mutableListOf<Pair<OnlineExtension, ResultRow>>()
val extensionsToInsert = mutableListOf<OnlineExtension>()
val extensionsToDelete =
installedExtensions.filter { it.value[ExtensionTable.repo] != null }.mapNotNull { (pkgName, extension) ->
extension.takeUnless { foundExtensions.any { it.pkgName == pkgName } }
extension.takeUnless { uniqueExtensions.any { it.pkgName == pkgName } }
}
foundExtensions.forEach {
uniqueExtensions.forEach {
val extension = installedExtensions[it.pkgName]
if (extension != null) {
extensionsToUpdate.add(it to extension)
Expand Down

0 comments on commit 02a7827

Please sign in to comment.