Skip to content

Commit

Permalink
Prevent UserIdentity metadata table from growing
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Jan 10, 2022
1 parent 952a194 commit 8d4a209
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 15 additions & 6 deletions src/realm/object-store/sync/impl/sync_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,23 @@ void SyncUserMetadata::set_identities(std::vector<SyncUserIdentity> 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<String>(c_sync_user_id, identities[i].id);
obj.set<String>(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<String>(c_sync_user_id, ident.id);
obj.set<String>(c_sync_provider_type, ident.provider_type);
obj_key = obj.get_key();
}
link_list.add(obj_key);
}

m_realm->commit_transaction();
Expand Down

0 comments on commit 8d4a209

Please sign in to comment.