From e23028dc30b0a13c73c94f806c1a3960bfdc9125 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 29 Jul 2022 12:34:59 -0700 Subject: [PATCH] Check if there are any new versions before refreshing in SubscriptionSet --- CHANGELOG.md | 3 +-- src/realm/sync/subscriptions.cpp | 13 ++++++++----- src/realm/sync/subscriptions.hpp | 3 +++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e92543cc0..d501aad2408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,11 @@ * (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. diff --git a/src/realm/sync/subscriptions.cpp b/src/realm/sync/subscriptions.cpp index 9d77f0ad8c5..40a09da3787 100644 --- a/src/realm/sync/subscriptions.cpp +++ b/src/realm/sync/subscriptions.cpp @@ -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::get_state_change_notification(State notify_when) const @@ -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 diff --git a/src/realm/sync/subscriptions.hpp b/src/realm/sync/subscriptions.hpp index 267b9a5aa14..1515bf93346 100644 --- a/src/realm/sync/subscriptions.hpp +++ b/src/realm/sync/subscriptions.hpp @@ -328,6 +328,9 @@ class SubscriptionStore : public std::enable_shared_from_this // 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>; TableSet get_tables_for_latest(const Transaction& tr) const;