From 69cefd052eab1f1f663f3c1f2b49ceec7e281e8c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 13 Apr 2016 12:48:15 -0700 Subject: [PATCH] Deliver the new TableView even if it did not change Even if the new TV has the same rows as the old one, we need to hand it over to the destination thread to bump the outside version of the destination thread's TV to avoid rerunning the query there. --- src/impl/results_notifier.cpp | 33 +++++++++++++++++++++------------ src/impl/results_notifier.hpp | 3 +++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/impl/results_notifier.cpp b/src/impl/results_notifier.cpp index dcd51b8e..f53f060d 100644 --- a/src/impl/results_notifier.cpp +++ b/src/impl/results_notifier.cpp @@ -73,7 +73,7 @@ bool ResultsNotifier::do_add_required_change_info(TransactionChangeInfo& info) return m_initial_run_complete && have_callbacks(); } -void ResultsNotifier::run() +bool ResultsNotifier::need_to_run() { REALM_ASSERT(m_info); REALM_ASSERT(!m_tv.is_attached()); @@ -82,7 +82,7 @@ void ResultsNotifier::run() auto lock = lock_target(); // Don't run the query if the results aren't actually going to be used if (!get_realm() || (!have_callbacks() && !m_target_results->wants_background_updates())) { - return; + return false; } } @@ -91,16 +91,15 @@ void ResultsNotifier::run() // Make an empty tableview from the query to get the table version, since // Query doesn't expose it if (m_query->find_all(0, 0, 0).sync_if_needed() == m_last_seen_version) { - return; + return false; } } - m_tv = m_query->find_all(); - if (m_sort) { - m_tv.sort(m_sort.column_indices, m_sort.ascending); - } - m_last_seen_version = m_tv.sync_if_needed(); + return true; +} +void ResultsNotifier::calculate_changes() +{ size_t table_ndx = m_query->get_table()->get_index_in_group(); if (m_initial_run_complete) { auto changes = table_ndx < m_info->tables.size() ? &m_info->tables[table_ndx] : nullptr; @@ -129,10 +128,6 @@ void ResultsNotifier::run() m_sort || m_from_linkview); m_previous_rows = std::move(next_rows); - if (m_changes.empty()) { - m_tv = {}; - return; - } } else { m_previous_rows.resize(m_tv.size()); @@ -141,6 +136,20 @@ void ResultsNotifier::run() } } +void ResultsNotifier::run() +{ + if (!need_to_run()) + return; + + m_tv = m_query->find_all(); + if (m_sort) { + m_tv.sort(m_sort.column_indices, m_sort.ascending); + } + m_last_seen_version = m_tv.sync_if_needed(); + + calculate_changes(); +} + void ResultsNotifier::do_prepare_handover(SharedGroup& sg) { if (!m_tv.is_attached()) { diff --git a/src/impl/results_notifier.hpp b/src/impl/results_notifier.hpp index 3dfc81f6..03b4be60 100644 --- a/src/impl/results_notifier.hpp +++ b/src/impl/results_notifier.hpp @@ -62,6 +62,9 @@ private: // can lead to deliver() being called before that bool m_initial_run_complete = false; + bool need_to_run(); + void calculate_changes(); + void run() override; void do_prepare_handover(SharedGroup&) override; bool do_deliver(SharedGroup& sg) override;