Skip to content

Commit

Permalink
Check if there are any new versions before refreshing in SubscriptionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Aug 4, 2022
1 parent e62f7c9 commit e23028d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* Allow multiple anonymous sessions. ([PR #5693](https://github.com/realm/realm-core/pull/5693)).
* Introducing query parser support for constant list expressions such as `fruit IN {'apple', 'orange'}`. This also includes general query support for list vs list matching such as `NONE fruits IN {'apple', 'orange'}`. ([Issue #4266](https://github.com/realm/realm-core/issues/4266))
* SubscriptionSet::refresh() does less work if no commits have been made since the last call to refresh(). ([PR #5695](https://github.com/realm/realm-core/pull/5695))

### Fixed
* Fix error message when validating outgoing links from asymmetric objects to non-embedded objects. ([PR #5702](https://github.com/realm/realm-core/pull/5702))



### Breaking changes
* None.

Expand Down
13 changes: 8 additions & 5 deletions src/realm/sync/subscriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,9 @@ MutableSubscriptionSet SubscriptionSet::make_mutable_copy() const
void SubscriptionSet::refresh()
{
auto mgr = get_flx_subscription_store(); // Throws
auto refreshed_self = mgr->get_by_version(version());
m_state = refreshed_self.m_state;
m_error_str = refreshed_self.m_error_str;
m_cur_version = refreshed_self.m_cur_version;
*this = mgr->get_by_version(version());
if (mgr->would_refresh(m_cur_version)) {
*this = mgr->get_by_version(version());
}
}

util::Future<SubscriptionSet::State> SubscriptionSet::get_state_change_notification(State notify_when) const
Expand Down Expand Up @@ -832,4 +830,9 @@ MutableSubscriptionSet SubscriptionStore::make_mutable_copy(const SubscriptionSe
return new_set_obj;
}

bool SubscriptionStore::would_refresh(DB::version_type version) const noexcept
{
return version < m_db->get_version_of_latest_snapshot();
}

} // namespace realm::sync
3 changes: 3 additions & 0 deletions src/realm/sync/subscriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ class SubscriptionStore : public std::enable_shared_from_this<SubscriptionStore>
// affect the mutable subscription identified by the parameter.
void supercede_all_except(MutableSubscriptionSet& mut_sub) const;

// Returns true if there have been commits to the DB since the given version
bool would_refresh(DB::version_type version) const noexcept;

using TableSet = std::set<std::string, std::less<>>;
TableSet get_tables_for_latest(const Transaction& tr) const;

Expand Down

0 comments on commit e23028d

Please sign in to comment.