mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-03 10:13:42 +00:00
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.
This commit is contained in:
parent
83b4d8ded2
commit
69cefd052e
@ -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()) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user