Skip to content

Commit

Permalink
Remove SyncUser::operator==()
Browse files Browse the repository at this point in the history
It had incorrect semantics (users from different Apps which happened to have
the same id would compare equal), and simply isn't neccesary as there should
only ever be a single SyncUser instance per user and so pointer equality
suffices.
  • Loading branch information
tgoyne committed Aug 2, 2023
1 parent 696af71 commit a30ab33
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Breaking changes
* SyncUser::provider_type() and realm_user_get_auth_provider() have been removed. Users don't have provider types; identities do.
* SyncUser no longer has a `local_identity()`. `identity()` has been guaranteed to be unique per App ever since v10.
* SyncUser no longer overrides operator==. Pointer equality should be used to compare sync users.

### Compatibility
* Fileformat: Generates files with format v23. Reads and automatically upgrade from fileformat v5.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/c_api/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ struct realm_user : realm::c_api::WrapC, std::shared_ptr<realm::SyncUser> {
bool equals(const WrapC& other) const noexcept final
{
if (auto ptr = dynamic_cast<const realm_user*>(&other)) {
return *get() == *(ptr->get());
return get() == ptr->get();
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/impl/realm_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void RealmCoordinator::set_config(const Realm::Config& config)
if (config.sync_config) {
auto old_user = m_config.sync_config->user;
auto new_user = config.sync_config->user;
if (old_user && new_user && *old_user != *new_user) {
if (old_user != new_user) {
throw LogicError(
ErrorCodes::MismatchedConfig,
util::format("Realm at path '%1' already opened with different sync user.", config.path));
Expand Down
11 changes: 0 additions & 11 deletions src/realm/object-store/sync/sync_user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,6 @@ class SyncUser : public std::enable_shared_from_this<SyncUser>, public Subscriba
m_seconds_to_adjust_time_for_testing.store(seconds);
}

/// Check the SyncUsers passed as argument have the same remote identity id.
friend bool operator==(const SyncUser& lhs, const SyncUser& rhs)
{
return lhs.identity() == rhs.identity();
}

friend bool operator!=(const SyncUser& lhs, const SyncUser& rhs)
{
return !(lhs == rhs);
}

protected:
friend class SyncManager;
void detach_from_sync_manager() REQUIRES(!m_mutex);
Expand Down

0 comments on commit a30ab33

Please sign in to comment.