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

Check if there are any new versions before refreshing in SubscriptionSet #5695

Merged
merged 1 commit into from
Aug 5, 2022
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
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