Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the filtering of duplicate columns #6543

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
val missingColumns = entity.properties
.map { EntitiesTable.getPropertyColumn(it.first) }
.distinctBy { it.lowercase() }
.filterNot { columnNames.contains(it) }
.filterNot { columnName -> columnNames.any { it.equals(columnName, ignoreCase = true) } }

if (missingColumns.isNotEmpty()) {
databaseConnection.resetTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#save ignores case-insensitive duplicate properties`() {
fun `#save ignores case-insensitive duplicate new properties`() {
val repository = buildSubject()
val entity = Entity.New(
"1",
Expand All @@ -745,15 +745,26 @@ abstract class EntitiesRepositoryTest {
)

repository.save("things", entity)
var savedEntities = repository.getEntities("things")
val savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))
}

@Test
fun `#save ignores case-insensitive duplicate properties if one of them has already been saved`() {
val repository = buildSubject()
val entity = Entity.New(
"1",
"One",
properties = listOf(Pair("prop", "value"))
)

/**
* Attempt to save again to ensure that duplicate properties are correctly compared, not only
* within the current entity list, but also against properties already saved in the database.
*/
repository.save("things", entity)
var savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))

repository.save("things", entity.copy(properties = listOf(Pair("Prop", "value"))))
savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ class InMemEntitiesRepository : EntitiesRepository {

private fun updateLists(list: String, entity: Entity) {
lists.add(list)
listProperties.getOrPut(list) {
val properties = listProperties.getOrPut(list) {
mutableSetOf()
}.addAll(
}
properties.addAll(
entity
.properties
.distinctBy { it.first.lowercase() }
.map { it.first }
.distinctBy { it.lowercase() }
.filterNot { properties.any { property -> property.equals(it, ignoreCase = true) } }
)
}

Expand Down