Skip to content

Commit

Permalink
Merge pull request #6503 from grzesiek2010/COLLECT-6501
Browse files Browse the repository at this point in the history
Filter out case-insensitive duplicate properties
  • Loading branch information
seadowg authored Nov 18, 2024
2 parents 193dd38 + 0f515c3 commit 3f48164
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
val missingColumns = entity.properties
.map { EntitiesTable.getPropertyColumn(it.first) }
.filterNot { columnNames.contains(it) }
.distinctBy { it.lowercase() }

if (missingColumns.isNotEmpty()) {
databaseConnection.resetTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,19 @@ abstract class EntitiesRepositoryTest {
repository.updateListHash("wine", "2024")
assertThat(repository.getListHash("wine"), equalTo("2024"))
}

@Test
fun `#save ignores case-insensitive duplicate properties`() {
val repository = buildSubject()
val entity = Entity.New(
"1",
"One",
properties = listOf(Pair("prop", "value"), Pair("Prop", "value"))
)

repository.save("things", entity)
val savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ class InMemEntitiesRepository : EntitiesRepository {
lists.add(list)
listProperties.getOrPut(list) {
mutableSetOf()
}.addAll(entity.properties.map { it.first })
}.addAll(
entity
.properties
.distinctBy { it.first.lowercase() }
.map { it.first }
)
}

private fun mergeProperties(
Expand Down

0 comments on commit 3f48164

Please sign in to comment.