diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1c625d6dd..ad4b703b74d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Having links in a property of Mixed type would lead to ill-formed JSON output when serializing the database. ([#5125](https://github.com/realm/realm-core/issues/5125), since v11.0.0) * FLX sync QUERY messages are now ordered with UPLOAD messages ([#5135](https://github.com/realm/realm-core/pull/5135)) * Fixed race condition when waiting for state change notifications on FLX subscription sets that may have caused a hang ([#5146](https://github.com/realm/realm-core/pull/5146)) +* UserIdentity metadata table grows indefinitely. ([#5152](https://github.com/realm/realm-core/issues/5152), since v10.0.0) ### Breaking changes * FLX SubscriptionSet type split into SubscriptionSet and MutableSubscriptionSet to add type safety ([#5092](https://github.com/realm/realm-core/pull/5092)) diff --git a/src/realm/object-store/sync/impl/sync_metadata.cpp b/src/realm/object-store/sync/impl/sync_metadata.cpp index 4b4ced033ce..89eb49b84e8 100644 --- a/src/realm/object-store/sync/impl/sync_metadata.cpp +++ b/src/realm/object-store/sync/impl/sync_metadata.cpp @@ -578,14 +578,23 @@ void SyncUserMetadata::set_identities(std::vector identities) m_realm->begin_transaction(); auto link_list = m_obj.get_linklist(m_schema.identities_col); - + auto identities_table = link_list.get_target_table(); + auto col_user_id = identities_table->get_column_key(c_sync_user_id); + auto col_provider_type = identities_table->get_column_key(c_sync_provider_type); link_list.clear(); - for (size_t i = 0; i < identities.size(); i++) { - auto obj = link_list.get_target_table()->create_object(); - obj.set(c_sync_user_id, identities[i].id); - obj.set(c_sync_provider_type, identities[i].provider_type); - link_list.add(obj.get_key()); + for (auto& ident : identities) { + ObjKey obj_key = identities_table->where() + .equal(col_user_id, StringData(ident.id)) + .equal(col_provider_type, StringData(ident.provider_type)) + .find(); + if (!obj_key) { + auto obj = link_list.get_target_table()->create_object(); + obj.set(c_sync_user_id, ident.id); + obj.set(c_sync_provider_type, ident.provider_type); + obj_key = obj.get_key(); + } + link_list.add(obj_key); } m_realm->commit_transaction();